public void Decrypt(IUser user) { if (!IsEncrypt) { return; } if (!IsDownloaded) { throw new ArgumentException("An undownloaded message cannot decrypt"); } if (!user.IsAuthorized) { throw new ArgumentException("User is unauthorized, message cannot decrypt"); } ISecureManager secureManager = ModulesManager.GetSecureManager(); string password = secureManager.DecryptWithAes(user.EncryptedPassword); if (type != StashMessageType.Empty) { content = secureManager.DecryptWithAesHmac(content, password); } IsEncrypt = false; }
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(); } } }
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)); }