1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
3
* Copyright 2012 Red Hat, Inc,
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
* Written by: Matthias Clasen <mclasen@redhat.com>
27
#include <glib/gi18n.h>
29
#include <pwquality.h>
32
static pwquality_settings_t *
35
static pwquality_settings_t *settings;
37
if (settings == NULL) {
39
settings = pwquality_default_settings ();
40
if (pwquality_read_config (settings, NULL, (gpointer)&err) < 0) {
41
g_error ("failed to read pwquality configuration: %s\n", err);
53
if (pwquality_get_int_value (get_pwq (), PWQ_SETTING_MIN_LENGTH, &value) < 0) {
54
g_error ("Failed to read pwquality setting\n" );
66
rv = pwquality_generate (get_pwq (), 0, &res);
69
g_error ("Password generation failed: %s\n",
70
pwquality_strerror (NULL, 0, rv, NULL));
78
pw_strength (const gchar *password,
79
const gchar *old_password,
80
const gchar *username,
82
const gchar **long_hint,
86
gdouble strength = 0.0;
89
rv = pwquality_check (get_pwq (),
90
password, old_password, username,
93
if (rv == PWQ_ERROR_MIN_LENGTH) {
94
*hint = C_("Password strength", "Too short");
95
*long_hint = pwquality_strerror (NULL, 0, rv, auxerror);
99
*hint = C_("Password strength", "Not good enough");
100
*long_hint = pwquality_strerror (NULL, 0, rv, auxerror);
104
strength = CLAMP (0.01 * rv, 0.0, 1.0);
106
if (strength < 0.50) {
108
*hint = C_("Password strength", "Weak");
109
} else if (strength < 0.75) {
111
*hint = C_("Password strength", "Fair");
112
} else if (strength < 0.90) {
114
*hint = C_("Password strength", "Good");
117
*hint = C_("Password strength", "Strong");
124
*strength_level = level;