public void Encrypt(IUser user) { if (IsEncrypt) { return; } if (!IsDownloaded) { throw new ArgumentException("An undownloaded message cannot encrypt"); } if (!user.IsAuthorized) { throw new ArgumentException("User is unauthorized, message cannot encrypt"); } ISecureManager secureManager = ModulesManager.GetModulesManager().GetSecureManager(); string password = secureManager.DecryptWithAes(user.EncryptedPassword); if (type != StashMessageType.Empty) { content = secureManager.EncryptWithAesHmac(content, password); } IsEncrypt = true; }
public void CreateUser(long chatId, string password) { ISecureManager secureManager = ModulesManager.GetSecureManager(); if (IsUserExist(chatId)) { LogoutUser(chatId); using (UsersContext db = new UsersContext()) { UserModel userModel = db.Users .Where(user => user.ChatId == chatId) .First(); userModel.HashPassword = secureManager.CalculateHash(password); db.SaveChanges(); } } else { using (UsersContext db = new UsersContext()) { UserModel userModel = new UserModel { ChatId = chatId, HashPassword = secureManager.CalculateHash(password) }; db.Users.Add(userModel); db.SaveChanges(); } } }
internal static ISecureManager GetSecureManager() { if (secureManager == null) { secureManager = new SecureManager(); } return(secureManager); }
private ModulesManager() { telegramBotClient = new TelegramBotClient(BotToken.Get()); messageManager = new MessageManager(); sessionManager = new SessionManager(); userManager = new UserManager(); secureManager = new SecureManager(); databaseManager = new DatabaseManager(); }
public void Login(string password) { if (string.IsNullOrEmpty(password)) { throw new ArgumentException("Password cannot be null"); } ISecureManager secureManager = ModulesManager.GetSecureManager(); EncryptedPassword = secureManager.EncryptWithAes(password); IsAuthorized = true; }
internal UserLocal(long chatId, string password) { if (string.IsNullOrEmpty(password)) { throw new ArgumentException("Password cannot be null"); } ISecureManager secureManager = ModulesManager.GetSecureManager(); ChatId = chatId; IsAuthorized = false; hashPassword = secureManager.CalculateHash(password); EncryptedPassword = null; }
public bool ValidatePassword(string password) { ISecureManager secureManager = ModulesManager.GetSecureManager(); return(secureManager.CompareWithHash(password, hashPassword)); }