using System; using System.Collections.Generic; using System.Linq; using SimpleHashing.Net; namespace Nibriboard.Userspace { public class User { private static ISimpleHash passwordHasher = new SimpleHash(); public DateTime CreationTime { get; set; } public string Username { get; set; } public string HashedPassword { get; set; } public List Roles { get; set; } public User() { } /// /// Updates this user's password. /// /// The new (unhashed) password. public void SetPassword(string newPassword) { HashedPassword = passwordHasher.Compute(newPassword); } /// /// Checks whether a specified (unhashed) password matches /// /// The password to check. /// Whether the specified password matches the stored password or not. public bool CheckPassword(string providedPassword) { return passwordHasher.Verify(providedPassword, HashedPassword); } /// /// Recursively works out whether this user has the specified permission. /// /// The permission to search for. /// Whether this user has the specified permission through one of their roles or not. public bool HasPermission(RbacPermission permission) { return Roles.Any((RbacRole role) => role.HasPermission(permission)); } } }