Skip to content

Commit

Permalink
Fixes a couple of user validation issues (#1028)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Payne authored and sebastienros committed Sep 27, 2017
1 parent 3e5d945 commit 1e475c9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/OrchardCore.Modules/OrchardCore.Setup/Views/Setup/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,43 @@
var options = identityOptions.Value;
var passwordOptions = new HtmlContentBuilder();
IHtmlContent separator = HtmlString.Empty;

if (options.Password.RequireNonAlphanumeric)
{
passwordOptions.AppendHtml(separator).AppendHtml(T["one non-alphanumeric"]);
separator = T[", "];
}

if (options.Password.RequireUppercase)
{
passwordOptions.AppendHtml(separator).AppendHtml(T["one uppercase"]);
separator = T[", "];
}

if (options.Password.RequireLowercase)
{
passwordOptions.AppendHtml(separator).AppendHtml(T["one lowercase"]);
separator = T[", "];
}

if (options.Password.RequireDigit)
{
passwordOptions.AppendHtml(separator).AppendHtml(T["one digit"]);
separator = T[", "];
}

if (separator != HtmlString.Empty)
{
separator = T[" and "];
}

passwordOptions.AppendHtml(separator).AppendHtml(T["{0} characters in total", options.Password.RequiredLength]);

if (options.Password.RequiredUniqueChars > 1)
{
passwordOptions.AppendHtml(T[", with {0} unique characters", options.Password.RequiredUniqueChars]);
}

var passwordTooltip = T["Password must have at least {0}.", passwordOptions];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public async Task<IUser> CreateUserAsync(string userName, string email, string[]
if (!identityResult.Succeeded)
{
ProcessValidationErrors(identityResult.Errors, user, reportError);
return null;
}

return user;
Expand Down Expand Up @@ -116,6 +117,9 @@ private void ProcessValidationErrors(IEnumerable<IdentityError> errors, User use
case "PasswordTooShort":
reportError("Password", T["Passwords must be at least {0} characters.", _identityOptions.Value.Password.RequiredLength]);
break;
case "PasswordRequiresUniqueChars":
reportError("Password", T["Passwords must contain at least {0} unique characters.", _identityOptions.Value.Password.RequiredUniqueChars]);
break;

// CurrentPassword
case "PasswordMismatch":
Expand Down

0 comments on commit 1e475c9

Please sign in to comment.