public async Task <InteractionResultSM> LoginAsync(LoginSM model) { var result = await _signInManager.PasswordSignInAsync(model.Username, model.Password, model.RememberLogin, lockoutOnFailure : false); if (result.Succeeded) { var user = await _signInManager.UserManager.FindByNameAsync(model.Username); await _events.RaiseAsync(new UserLoginSuccessEvent(user.UserName, user.Id, user.UserName)); return(InteractionResultSMFactory.CreateResult(user, result)); } await _events.RaiseAsync(new UserLoginFailureEvent(model.Username, "invalid credentials")); return(InteractionResultSMFactory.CreateResult(null, result)); }
public async Task <ServiceResult> AttemptLogin(LoginSM sm, bool biometric, string ip) { if (!biometric) { using var hasher = new SHA512Managed(); var codeBytes = Encoding.UTF8.GetBytes(sm.Password); var password = hasher.ComputeHash(codeBytes); sm.Password = BitConverter.ToString(password).Replace("-", string.Empty).ToLower(); } var user = await Db.Users.Include(x => x.Role).FirstOrDefaultAsync(x => x.Email.ToLower().Equals(sm.Email.ToLower()) && x.Password.Equals(sm.Password)); var ips = configuration.GetSection("AppSettings:WebAppIps").Get <List <string> >(); var isBypass = ips.Contains(ip); if (user == null) { ServiceResult.Errors.Add("Email or password is incorrect."); } else if (user.AppID != sm.AppID && !isBypass) { ServiceResult.Errors.Add("The device you are logging in from is not the one bound to your account."); } else if (user.Locked) { ServiceResult.Errors.Add("This account is locked. Please unlock through the web portal."); } else { string token = GenerateJwt(user); ServiceResult.Values.Add("token", token); ServiceResult.Values.Add("firstname", user.FirstName); ServiceResult.Values.Add("status", user.Status.ToString()); } return(ServiceResult); }