public async Task UpdateAuthentication(LoginPasswordUserAuthentication authentication) { await UseConnection(async connection => { await connection.UpdateAsync(authentication); }); }
public async Task UpdatePassword(LoginPasswordUserAuthentication authentication, string password) { await UseConnection(async connection => { authentication.Password = password.AsSha256(); await connection.UpdateAsync(authentication); }); }
public async Task <LoginPasswordUserAuthentication> CreateAuthenticationForUser(User user, string password) { return(await UseConnection(async connection => { LoginPasswordUserAuthentication authentication = new LoginPasswordUserAuthentication { CollationId = Guid.NewGuid(), UserId = user.Id, Login = user.Email, Password = password.AsSha256(), }; authentication.Id = await connection.InsertAsync(authentication, selectIdentity: true); return authentication; })); }
public async Task <IAuthentication> LoginWithCredentials(string login, string password) { return(await UseConnection(async connection => { LoginPasswordUserAuthentication authentication = await connection.From <LoginPasswordUserAuthentication>() .NotDeleted() .Where(x => x.Login == login) .AsSingleAsync(connection); if (authentication is null) { return null; } if (authentication.Password == password.AsSha256()) { return authentication; } return null; })); }
protected override async Task <Unit> Action(SetPasswordCommandParameter parameter) { if (parameter.Data.NewPassword.NotStrongPassword()) { throw new DomainException(Errors.WEAK_PASSWORD, "Password is too weak"); } ICredentialAuthenticationService authenticationService = Services.GetService <ICredentialAuthenticationService>(); LoginPasswordUserAuthentication credentials = await authenticationService.GetAuthenticationForUser(Account); if (credentials is null) { throw new DomainException(Errors.NO_CREDENTIALS, "No credentials for this user"); } if (parameter.Data.OldPassword.AsSha256() != credentials.Password) { throw new DomainException(Errors.INVALID_PASSWORD, "Invalid old password"); } await authenticationService.UpdatePassword(credentials, parameter.Data.NewPassword); return(Unit.Default); }