public int getEmpXCredenciales(string userName, string password) { try { using (TeamCellContext _dbContext = new TeamCellContext()) { var user = _dbContext.User.FirstOrDefault(x => x.UserName == userName); if (user != null) { byte[] hashedPassword = Cryptographic.HashPasswordWithSalt(Encoding.UTF8.GetBytes(password), user.Salt); if (hashedPassword.SequenceEqual(user.Password)) { return(user.IdEmployee); } else { return(0); } } return(0); } } catch (Exception) { return(0); } }
//private readonly TeamCellContext _dbContext = new TeamCellContext(); //public UserController(TeamCellContext dbContext) //{ // _dbContext = dbContext; //} private User convertToUser(TempUser userTmp) { var user = new User(); user.UserName = userTmp.UserName; user.Salt = Cryptographic.GenerateSalt(); user.Password = Cryptographic.HashPasswordWithSalt(Encoding.UTF8.GetBytes(userTmp.Password), user.Salt); user.IdEmployee = userTmp.IdEmployee; user.Status = userTmp.Status; return(user); }