Skip to content

Commit

Permalink
Merge pull request #143 from zlamalp/mu
Browse files Browse the repository at this point in the history
Added password strength check for MU namespace
  • Loading branch information
zlamalp authored Feb 16, 2021
2 parents 1fe030b + 7f8666c commit dba6c76
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,13 @@ public interface PerunTranslation extends Messages {
@DefaultMessage("Password <b>can`t contain login, name or surname</b>, not even backwards!")
public String einfraPasswordStrengthForNameLogin();

@DefaultMessage("Password must <ul><li>be at least 12 characters long<li>consist of at least 3 of 4 character groups<ul><li>lower-case letters<li>upper-case letters<li>digits<li>special characters</ul></ul>")
public String muPasswordHelp();

@DefaultMessage("Password must be <b>at least 12 characters</b> long!")
public String muPasswordLength();

@DefaultMessage("Password must consist of <b>at least 3 of 4</b> character groups<ul><li>lower-case letters</li><li>upper-case letters</li><li>digits</li><li>special characters</li></ul>")
public String muPasswordStrength();

}
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,6 @@ einfraPasswordLength=Heslo musí mít <b>alespoň 10 znaků!</b>
einfraPasswordFormat=Heslo <b>nesmí obsahovat diakritiku</b> nebo řídící a formátovací znaky!</b>
einfraPasswordStrength=Heslo musí obsahovat <b>alespoň 3 ze 4</b> kategorií znaků<ul><li>malá písmena</li><li>velká písmena</li><li>číslice</li><li>speciální znaky</li></ul>
einfraPasswordStrengthForNameLogin=Heslo <b>nesmí obsahovat login, jméno nebo příjmení</b> a to ani pozpátku!
muPasswordHelp=Heslo musí<ul><li>mít délku 12 a více znaků<li>obsahovat alespoň 3 ze 4 kategorií znaků<ul><li>malá písmena<li>velká písmena<li>číslice<li>speciální znaky</ul></ul>
muPasswordLength=Heslo musí mít <b>alespoň 12 znaků!</b>
muPasswordStrength=Heslo musí obsahovat <b>alespoň 3 ze 4</b> kategorií znaků<ul><li>malá písmena</li><li>velká písmena</li><li>číslice</li><li>speciální znaky</li></ul>
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ public void onFinished(JavaScriptObject result) {
help.setHTML("<p>" + translation.einfraPasswordHelp());
} else if (Objects.equals(namespace, "vsup")) {
help.setHTML("<p>"+translation.vsupHelp());
} else if (Objects.equals(namespace, "mu")) {
help.setHTML("<p>"+translation.muPasswordHelp());
}

return;
Expand Down Expand Up @@ -509,6 +511,34 @@ private boolean validate() {
return false;
}

} else if (Objects.equals(namespace, "mu")) {

// Check that password contains at least 3 of 4 character groups

RegExp regExpDigit = RegExp.compile("^.*[0-9].*$");
RegExp regExpLower = RegExp.compile("^.*[a-z].*$");
RegExp regExpUpper = RegExp.compile("^.*[A-Z].*$");
RegExp regExpSpec = RegExp.compile("^.*[\\x20-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7E].*$"); // FIXME - are those correct printable specific chars?

int matchCounter = 0;
if (regExpDigit.exec(passwordTextBox.getValue()) != null) matchCounter++;
if (regExpLower.exec(passwordTextBox.getValue()) != null) matchCounter++;
if (regExpUpper.exec(passwordTextBox.getValue()) != null) matchCounter++;
if (regExpSpec.exec(passwordTextBox.getValue()) != null) matchCounter++;

if(matchCounter < 3){
passItem.setValidationState(ValidationState.ERROR);
itemStatus.setHTML(translation.muPasswordStrength());
return false;
}

// check length
if (passwordTextBox.getValue().length() < 12) {
passItem.setValidationState(ValidationState.ERROR);
itemStatus.setHTML(translation.muPasswordLength());
return false;
}

}

if (!Objects.equals(passwordTextBox.getValue(), passwordTextBox2.getValue())) {
Expand Down

0 comments on commit dba6c76

Please sign in to comment.