コード例 #1
0
void AddUserDlg::slotCheckPwd()
{
    ui.infoLabel->setText("");

    if (ui.canLoginCheckBox->isChecked()) {
        if (!checkPwd()) {
            return;
        }

    }

    if (true) {
        char pwdStr[512] ="";
        char userName[128]="";
        if( ui.userNameEdit->text().trimmed().length() < 1 ) {
            ui.infoLabel->setText(i18n("Please input user name."));
            ui.userNameEdit->selectAll();
            return;
        }
        pwdStr[0] = '\0';
        userName[0] = '\0';
        snprintf(pwdStr,sizeof(pwdStr),"%s",qPrintable(ui.PwdEdit->text()) );
        snprintf(userName,sizeof(userName),"%s",qPrintable(ui.userNameEdit->text().trimmed() ) );
        void *auxerror;
        int pwdErrValue = 0;
        int pwdValue = pwquality_check (get_pwq (),
                            pwdStr, NULL, userName,&auxerror);
        if( pwdValue < 0 ) {
            pwdErrValue = 0;
            QString  setStr = pwdErrorStr(pwdValue,&pwdErrValue);
            if( pwdErrValue > 0 ) {
                int i = ui.PwdEdit->text().length();
                if( i < 0 ) {
                    i = 1;
                }
                pwdErrValue = 2*i;
                if( pwdErrValue >100 ) {
                    pwdErrValue = 100;
                }
                ui.pwdProgressBar->setValue(pwdErrValue);
            }
            else {
                ui.infoLabel->setText(setStr);
                ui.PwdEdit->selectAll();
                ui.pwdProgressBar->setValue(0);
                return;
            }
        }
        else {
            ui.pwdProgressBar->setValue(pwdValue);
        }
    }

    if( ui.verifyPwdEdit->text() !=  ui.PwdEdit->text() ){
        ui.infoLabel->setText(i18n("Passwords do not match."));
        return;
    }
}
コード例 #2
0
gint
pw_min_length (void)
{
    gint value = 0;

    if (pwquality_get_int_value (get_pwq (), PWQ_SETTING_MIN_LENGTH, &value) < 0) {
        g_error ("Failed to read pwquality setting\n" );
    }

    return value;
}
コード例 #3
0
gchar *
pw_generate (void)
{
    gchar *res;
    gint rv;

    rv = pwquality_generate (get_pwq (), 0, &res);

    if (rv < 0) {
        g_error ("Password generation failed: %s\n",
                 pwquality_strerror (NULL, 0, rv, NULL));
        return NULL;
    }

    return res;
}
コード例 #4
0
gdouble
pw_strength (const gchar  *password,
             const gchar  *old_password,
             const gchar  *username,
             const gchar **hint,
             gint         *strength_level)
{
        gint rv, level, length = 0;
        gdouble strength = 0.0;
        void *auxerror;

        rv = pwquality_check (get_pwq (),
                              password, old_password, username,
                              &auxerror);

        if (password != NULL)
                length = strlen (password);

        strength = CLAMP (0.01 * rv, 0.0, 1.0);
        if (rv < 0) {
                level = (length > 0) ? 1 : 0;
        }
        else if (strength < 0.50) {
                level = 2;
        } else if (strength < 0.75) {
                level = 3;
        } else if (strength < 0.90) {
                level = 4;
        } else {
                level = 5;
        }

        if (length && length < pw_min_length())
                *hint = pw_error_hint (PWQ_ERROR_MIN_LENGTH);
        else
                *hint = pw_error_hint (rv);

        if (strength_level)
                *strength_level = level;

        return strength;
}
コード例 #5
0
gdouble
pw_strength (const gchar  *password,
             const gchar  *old_password,
             const gchar  *username,
             const gchar **hint,
             const gchar **long_hint,
             gint         *strength_level)
{
    gint rv, level = 0;
    gdouble strength = 0.0;
    void *auxerror;

    rv = pwquality_check (get_pwq (),
                          password, old_password, username,
                          &auxerror);

    strength = CLAMP (0.01 * rv, 0.0, 1.0);
    if (rv < 0) {
        *hint = C_("Password strength", "Strength: Weak");
    }
    else if (strength < 0.50) {
        level = 1;
        *hint = C_("Password strength", "Strength: Low");
    } else if (strength < 0.75) {
        level = 2;
        *hint = C_("Password strength", "Strength: Medium");
    } else if (strength < 0.90) {
        level = 3;
        *hint = C_("Password strength", "Strength: Good");
    } else {
        level = 4;
        *hint = C_("Password strength", "Strength: High");
    }

    *long_hint = pw_error_hint (rv);

    if (strength_level)
        *strength_level = level;

    return strength;
}