Back to Coding

Admin User Management Setup

Prompt

You are a professional programmer tasked with developing a user management system for a web server project using the following specifications: 1. **User Registration:** Implement a one-sided registration system performed exclusively via the console (no UI registration). 2. **Login:** Create a login system accessible through a web page. 3. **Session Persistence:** Implement cookie-based user session storage that keeps the user logged in for 24 hours only if the "remember me" checkbox is selected during login. 4. **Admin Page:** Develop and integrate the admin dashboard using an existing template which you can extend further. **Technical Stack and Tools:** - Backend framework: Express.js - Database: MongoDB using Mongoose ODM - Template Engine for front end: EJS - Password hashing: bcrypt - Session/Cookie Management: Recommend and implement the most suitable package (e.g., express-session vs jsonwebtoken), with a focus on security and ease of use. **Existing Project Information:** - Files available: server.js, errorHandle.js, project folder structure, and .env configuration (including environment variables). - No current middleware for authentication or authorization. **User Schema Requirements:** - Fields: username, email, hashed password, role (only "admin" role exists), timestamps. - No role-based access control beyond "admin". **Frontend:** - Admin panel template is ready to be integrated (or needs to be created). - CSS Framework: Bootstrap - Responsive design is required. **Security:** - Rate limiting to 5 login attempts to prevent brute force attacks. **Task Instructions:** - Specify all resources, files, or information you need to begin development. - Include detailed steps and recommendations to implement the system considering scalability and maintainability. - Provide clear reasoning behind technology choices, especially for session management. # Steps 1. Review the existing code and folder structure. 2. Define the user schema with Mongoose including necessary validations. 3. Implement console-based registration script. 4. Develop login functionality with Express.js and EJS, including "remember me" cookie logic. 5. Setup session or token management with selected libraries. 6. Implement login attempt rate limiting. 7. Integrate admin template and ensure responsiveness with Bootstrap. 8. Secure all routes, especially administrative ones. # Output Format Provide a detailed implementation plan that includes: - The exact list of resources/files you require. - A step-by-step development plan. - Suggested code snippets or pseudocode for critical parts. - Justifications for technology and design decisions. - Any additional notes on security, scalability, or user experience. # Notes - Consider best practices for password hashing and cookie security. - Suggest improvements where applicable, such as adding middleware. - Keep explanations clear and professional to guide the implementation thoroughly. Your response must be comprehensive and structured to enable smooth development of the described user management system.

Related Coding Prompts

Write Code

As a seasoned programmer, your task is to write code in [programming language] to [perform action]. The code should be efficient, well-structured, and optimized for performance. Make sure to follow best practices and industry standards while implementing the necessary algorithms and logic to achieve the desired functionality. Test the code thoroughly to ensure it functions as intended and meets all requirements. Additionally, document the code properly for future reference and maintenance.

Debug Code

Act as a seasoned programmer with over 20 years of commercial experience. Analyze the provided [piece of code] that is causing a specific [error]. Your task involves diagnosing the root cause of the error, understanding the context and functionality intended by the code, and proposing a solution to fix the issue. Your analysis should include a step-by-step walkthrough of the code, identification of any bugs or logical mistakes, and a detailed explanation of how to resolve them. Additionally, suggest any improvements or optimizations to enhance the performance, readability, or maintainability of the code based on your extensive experience. Ensure that your solution adheres to best practices in software development and is compatible with the current development environment where the code is being executed.

Do Code Review

As a seasoned programmer with over 20 years of commercial experience, your task is to perform a comprehensive code review on the provided [piece of code]. Your review should meticulously evaluate the code's efficiency, readability, and maintainability. You are expected to identify any potential bugs, security vulnerabilities, or performance issues and suggest specific improvements or optimizations. Additionally, assess the code's adherence to industry standards and best practices. Your feedback should be constructive and detailed, offering clear explanations and recommendations for changes. Where applicable, provide examples or references to support your suggestions. Your goal is to ensure that the code not only functions as intended but also meets high standards of quality and can be easily managed and scaled in the future. This review is an opportunity to mentor and guide less experienced developers, so your insights should be both educational and actionable.