A secure, multi-user password management application built with C# WPF using LINQ to SQL and following the MVVM pattern. The application demonstrates essential security features including password encryption, two-factor authentication, and role-based access control.
- Framework: .NET Framework 4.8
- UI: Windows Presentation Foundation (WPF)
- Architecture: Model-View-ViewModel (MVVM)
- Database: Microsoft SQL Server with LINQ to SQL
- Security: AES encryption, PBKDF2 password hashing, TOTP-based 2FA
The solution consists of three projects with clear separation of concerns:
graph TD
A[PasswordManager.App] --> B[PasswordManager.Core]
A --> C[PasswordManager.Data]
C --> B
- Contains core business logic and interfaces
- Defines models and service interfaces
- Implements security services and MVVM base classes
- Has no dependencies on other projects
- Handles data access using LINQ to SQL
- Implements repository pattern
- References only PasswordManager.Core
- Contains database mappings and configurations
- WPF user interface implementation
- Contains Views and ViewModels
- References both Core and Data projects
- Implements UI-specific converters and services
- Uses AES encryption for stored passwords
- Implements secure key management
- Example from
EncryptionService.cs
:
public string Encrypt(string plainText)
{
using (Aes aes = Aes.Create())
{
aes.Key = Convert.FromBase64String(_key);
aes.IV = _iv;
ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV);
// ... encryption implementation
}
}
- TOTP-based 2FA using standard algorithms
- QR code generation for easy setup
- Secure secret key management
- Example usage from
SecurityService.cs
:
public bool ValidateTwoFactorCode(string secretKey, string code)
{
var keyBytes = Base32Encoding.ToBytes(secretKey);
var totp = new Totp(keyBytes);
return totp.VerifyTotp(code, out long timeStepMatched, window);
}
The application supports three user roles:
graph TD
A[User Roles] --> B[User]
A --> C[Administrator]
A --> D[IT Specialist]
B --> B1[Manage own passwords]
B --> B2[Enable/disable 2FA]
C --> C1[Manage users]
C --> C2[Reset passwords]
C --> C3[View audit logs]
D --> D1[Monitor login attempts]
D --> D2[View security metrics]
D --> D3[Generate security reports]
- User: Basic password management and 2FA setup
- Administrator: User management and system auditing
- IT Specialist: Security monitoring and threat analysis
Each major feature has its own ViewModel inheriting from ViewModelBase
:
public abstract class ViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
Uses RelayCommand
for MVVM command pattern implementation:
public class RelayCommand : ICommand
{
private readonly Action<object> _execute;
private readonly Func<object, bool> _canExecute;
public RelayCommand(Action<object> execute, Func<object, bool> canExecute = null)
{
_execute = execute ?? throw new ArgumentNullException(nameof(execute));
_canExecute = canExecute;
}
}
erDiagram
Users ||--o{ StoredPasswords : has
Users ||--o{ AuditLog : generates
Users }|--|| Roles : has
Users {
int UserId PK
string Username
string PasswordHash
string Email
int RoleId FK
boolean TwoFactorEnabled
string TwoFactorSecret
datetime LastLoginDate
}
StoredPasswords {
int PasswordId PK
int UserId FK
string SiteName
string SiteUrl
string Username
string EncryptedPassword
datetime CreatedDate
}
Roles {
int RoleId PK
string RoleName
}
AuditLog {
int LogId PK
int UserId FK
datetime ActionDate
string Action
string Details
}
The application implements the repository pattern for data access:
public interface IStoredPasswordRepository
{
StoredPasswordModel GetById(int passwordId);
IEnumerable<StoredPasswordModel> GetByUserId(int userId);
void Create(StoredPasswordModel password);
void Update(StoredPasswordModel password);
void Delete(int passwordId);
}
- Create the database using the provided SQL scripts
- Update the connection string in
App.config
- Generate an encryption key using the provided utility
- Build and run the application
-
Password Management
- Secure storage of passwords
- Password generation
- Password strength evaluation
- Password expiration tracking
-
Security Monitoring
- Failed login tracking
- Suspicious activity detection
- Audit logging
- Security metrics dashboard
-
User Administration
- User account management
- Role assignment
- Password reset functionality
- Activity monitoring
-
Separation of Concerns
- Clear project structure
- MVVM pattern implementation
- Repository pattern for data access
-
Security
- Secure password storage
- Two-factor authentication
- Encryption for sensitive data
- Audit logging
-
SOLID Principles
- Interface segregation
- Dependency injection
- Single responsibility
-
Code Organization
- Consistent naming conventions
- Clear folder structure
- Proper use of interfaces
- Service-based architecture