A simple C# console application for managing users using PostgreSQL. This project demonstrates secure password hashing, basic CRUD functionality, and clean architecture using principles like SOLID and separation of concerns.
- Add new users (name, email, password)
- Secure password hashing with SHA256
- Email uniqueness check
- View all users
- Automatic table creation on startup
- .NET Core / .NET 6+
- PostgreSQL
- Npgsql (PostgreSQL driver for .NET)
- Create a PostgreSQL database named
Users. - Update the connection string in the code if necessary:
string connectionString = "Host=localhost;Port=5432;Database=Users;Username=postgres;Password=326451;";dotnet build
dotnet run├── Program.cs // Entry point
├── App.cs // CLI logic and menu
├── Services/
│ └── UserService.cs // Business logic for user operations
├── Repositories/
│ └── UserRepository.cs // Data access layer for PostgreSQL
├── Models/
│ └── User.cs // User entity
├── Utils/
│ └── PasswordHasher.cs // SHA256 hashing utility
└── Database/
└── DatabaseInitializer.cs // Table creation logic
- SOLID: Each class has a single responsibility.
- Separation of Concerns: Clear separation between data, business logic, and user interface.
- Extensibility: The design makes it easy to extend, test, and refactor.
Enter name: John
Enter email: john@example.com
Enter password: mysecurepassword
ID: 1
Name: John
Email: john@example.com
Created At: 2025-04-03 10:20:33
- Passwords are stored securely as SHA256 hashes.
- Duplicate emails are not allowed.
This project is open-source and provided as-is for learning and experimentation.