public int UpdatePassword(string phoneNumber, List <string> passwords) { var account = _context.Accounts.FirstOrDefault(x => x.PhoneNum == phoneNumber); if (account != null) { if (BcryptPass.ValidatePassword(passwords[0], account.Password)) { account.Password = BcryptPass.HashPassword(passwords[1]); try { _context.SaveChanges(); return(1); } catch (Exception) { return(-1); } } else { return(0); } } return(-1); }
public int Register(AccountDTO accountDTO) { var count = _context.Accounts.Count(x => x.PhoneNum == accountDTO.PhoneNum); if (count > 0) { return(0); } var account = new Account(); account.PhoneNum = accountDTO.PhoneNum; account.Password = BcryptPass.HashPassword(accountDTO.Password); account.RoleId = 2; account.Fullname = accountDTO.Fullname; try { _context.Accounts.Add(account); _context.SaveChanges(); return(1); } catch (Exception e) { return(-1); } }
public static Account toAccount(AccountDTO accountDTO) { var account = new Account { PhoneNum = accountDTO.PhoneNum, Password = BcryptPass.HashPassword(accountDTO.Password), Fullname = accountDTO.Fullname, RoleId = 2 }; return(account); }
public int Login(string phoneNumber, string password) { var user = _context.Accounts.FirstOrDefault(x => x.PhoneNum == phoneNumber); if (user == null) { return(0); } if (BcryptPass.ValidatePassword(password, user.Password)) { return(1); } return(-1); }