public Task ValidateAsync(ResourceOwnerPasswordValidationContext context) { try { if (string.IsNullOrWhiteSpace(context.UserName) || string.IsNullOrWhiteSpace(context.Password)) { context.Result = new GrantValidationResult(TokenRequestErrors.InvalidRequest, "user name and password must fill"); } var password = PwdHandler.MD5EncryptTo32(context.Password); var res = _developerServer.GetDeveloperByAccount(new DeveloperQuery { Name = context.UserName, Secret = password }).GetAwaiter().GetResult(); if (res.Name == context.UserName && res.Secret == password) { context.Result = new GrantValidationResult( subject: context.UserName, authenticationMethod: OidcConstants.AuthenticationMethods.Password, claims: GetClaims(res)); } else { context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, "Wrong user name or password"); } return(Task.FromResult(0)); } catch (Exception ex) { _log.Error("ValidateAsync method error:" + ex); context.Result = new GrantValidationResult(TokenRequestErrors.InvalidRequest, ex.Message); return(Task.FromResult(0)); } }
public void GetPwdContent() { var sut = PwdHandler.MD5EncryptTo32("tourismPwd"); Assert.NotNull(sut); }