Search in sources :

Example 1 with StrengthInfo

use of pl.edu.icm.unity.stdext.credential.pass.StrengthChecker.StrengthInfo in project unity by unity-idm.

the class StrengthCheckerTest method shouldReturnLowScoreForBadPassword.

@Test
public void shouldReturnLowScoreForBadPassword() throws IOException {
    MessageSource msg = mock(MessageSource.class);
    when(msg.getMessage(eq("feedback.repeat.warning.likeABCABCABC"), any(), any())).thenReturn("ok1");
    when(msg.getMessage(eq("feedback.extra.suggestions.addAnotherWord"), any(), any())).thenReturn("o2k");
    when(msg.getMessage(eq("feedback.repeat.suggestions.avoidRepeatedWords"), any(), any())).thenReturn("ok3");
    StrengthInfo result = StrengthChecker.measure("soso", 10, Locale.ENGLISH, msg);
    assertThat("" + result.scoreNormalized, result.scoreNormalized < 0.15, is(true));
}
Also used : StrengthInfo(pl.edu.icm.unity.stdext.credential.pass.StrengthChecker.StrengthInfo) MessageSource(pl.edu.icm.unity.MessageSource) Test(org.junit.Test)

Example 2 with StrengthInfo

use of pl.edu.icm.unity.stdext.credential.pass.StrengthChecker.StrengthInfo in project unity by unity-idm.

the class PasswordQualityComponent method onNewPassword.

public void onNewPassword(String password) {
    StrengthInfo measure = StrengthChecker.measure(password, config.getMinScore(), msg);
    int length = password.length();
    boolean trivialSequences = StrengthChecker.hasNoTrivialSequences(password);
    int classes = StrengthChecker.getCharacterClasses(password);
    qualityMeter.setValue((float) measure.scoreNormalized);
    if (config.getMinScore() > 0) {
        boolean isScoreOK = measure.score >= config.getMinScore();
        Images qualityIcon = isScoreOK ? Images.ok : Images.warn;
        qualityMeter.setIcon(qualityIcon.getResource());
        qualityMeter.setStyleName(Styles.iconError.toString(), !isScoreOK);
        if (isScoreOK) {
            qualityMeter.removeStyleName(Styles.redProgressBar.toString());
            qualityMeter.setStyleName(Styles.greenProgressBar.toString());
        } else {
            qualityMeter.removeStyleName(Styles.greenProgressBar.toString());
            qualityMeter.setStyleName(Styles.redProgressBar.toString());
        }
    }
    if (!measure.warning.isEmpty()) {
        mainInfo.setValue(msg.getMessage("PasswordCredentialEditor.hint", measure.warning));
    } else if (!measure.suggestions.isEmpty()) {
        mainInfo.setValue(msg.getMessage("PasswordCredentialEditor.hint", measure.suggestions.get(0)));
    } else {
        mainInfo.setValue("");
    }
    styleStatusLabel(minLengthStatus, length >= config.getMinLength(), msg.getMessage("PasswordCredentialEditor.minLengthStatus", length, config.getMinLength()));
    styleStatusLabel(minClassesStatus, classes >= config.getMinClassesNum(), msg.getMessage("PasswordCredentialEditor.minClassesStatus", classes, config.getMinClassesNum()));
    styleStatusLabel(sequencesStatus, trivialSequences, msg.getMessage("PasswordCredentialEditor.trivialSequences"));
}
Also used : StrengthInfo(pl.edu.icm.unity.stdext.credential.pass.StrengthChecker.StrengthInfo) Images(pl.edu.icm.unity.webui.common.Images)

Example 3 with StrengthInfo

use of pl.edu.icm.unity.stdext.credential.pass.StrengthChecker.StrengthInfo in project unity by unity-idm.

the class StrengthCheckerTest method shouldReturnMaxScoreForGoodPassword.

@Test
public void shouldReturnMaxScoreForGoodPassword() throws IOException {
    MessageSource msg = mock(MessageSource.class);
    StrengthInfo result = StrengthChecker.measure("horsedonteathorseradishondisk", 10, Locale.ENGLISH, msg);
    assertThat("" + result.scoreNormalized, result.scoreNormalized, is(1.0));
}
Also used : StrengthInfo(pl.edu.icm.unity.stdext.credential.pass.StrengthChecker.StrengthInfo) MessageSource(pl.edu.icm.unity.MessageSource) Test(org.junit.Test)

Example 4 with StrengthInfo

use of pl.edu.icm.unity.stdext.credential.pass.StrengthChecker.StrengthInfo in project unity by unity-idm.

the class StrengthCheckerTest method shouldReturnWarningInSelectedLocale.

@Test
public void shouldReturnWarningInSelectedLocale() throws IOException {
    MessageSource msg = mock(MessageSource.class);
    when(msg.getMessage(eq("feedback.spatial.suggestions.UseLongerKeyboardPattern"), any(), eq(new Locale("pl")))).thenReturn("ok1");
    when(msg.getMessage(eq("feedback.repeat.suggestions.avoidRepeatedWords"), any(), any())).thenReturn("ok2");
    when(msg.getMessage(eq("feedback.extra.suggestions.addAnotherWord"), any(), any())).thenReturn("ok3");
    when(msg.getMessage(eq("feedback.spatial.warning.straightRowsOfKeys"), any(), any())).thenReturn("ok4");
    StrengthInfo result = StrengthChecker.measure("asdfghjkl;'", 10, new Locale("pl"), msg);
    assertThat(result.toString(), result.warning, is("ok4"));
}
Also used : Locale(java.util.Locale) StrengthInfo(pl.edu.icm.unity.stdext.credential.pass.StrengthChecker.StrengthInfo) MessageSource(pl.edu.icm.unity.MessageSource) Test(org.junit.Test)

Example 5 with StrengthInfo

use of pl.edu.icm.unity.stdext.credential.pass.StrengthChecker.StrengthInfo in project unity by unity-idm.

the class PasswordFieldsComponent method isValid.

private boolean isValid() {
    String password = this.password1.getValue();
    StrengthInfo measure = StrengthChecker.measure(password, config.getMinScore(), msg);
    if (measure.score < config.getMinScore())
        return false;
    if (password.length() < config.getMinLength())
        return false;
    if (StrengthChecker.getCharacterClasses(password) < config.getMinClassesNum())
        return false;
    if (config.isDenySequences() && !StrengthChecker.hasNoTrivialSequences(password))
        return false;
    return true;
}
Also used : StrengthInfo(pl.edu.icm.unity.stdext.credential.pass.StrengthChecker.StrengthInfo)

Aggregations

StrengthInfo (pl.edu.icm.unity.stdext.credential.pass.StrengthChecker.StrengthInfo)5 Test (org.junit.Test)3 MessageSource (pl.edu.icm.unity.MessageSource)3 Locale (java.util.Locale)1 Images (pl.edu.icm.unity.webui.common.Images)1