| 1 |
/***************************************************************************
|
| 2 |
passwd.c - description
|
| 3 |
-------------------
|
| 4 |
begin : Mon Oct 22 2004
|
| 5 |
copyright : (C) 2004 by Leaflet
|
| 6 |
email : leaflet@leafok.com
|
| 7 |
***************************************************************************/
|
| 8 |
|
| 9 |
/***************************************************************************
|
| 10 |
* *
|
| 11 |
* This program is free software; you can redistribute it and/or modify *
|
| 12 |
* it under the terms of the GNU General Public License as published by *
|
| 13 |
* the Free Software Foundation; either version 2 of the License, or *
|
| 14 |
* (at your option) any later version. *
|
| 15 |
* *
|
| 16 |
***************************************************************************/
|
| 17 |
|
| 18 |
#include <string.h>
|
| 19 |
|
| 20 |
int
|
| 21 |
verify_pass_complexity (const char *password, const char *username, int len)
|
| 22 |
{
|
| 23 |
int ch_repeat[128], i, verify_ok = 1, pass_len,
|
| 24 |
num_count = 0, upper_case = 0, lower_case = 0;
|
| 25 |
|
| 26 |
pass_len = strlen (password);
|
| 27 |
|
| 28 |
for (i = 0; i < 128; i++)
|
| 29 |
ch_repeat[i] = 0;
|
| 30 |
|
| 31 |
if (pass_len < len)
|
| 32 |
verify_ok = 0;
|
| 33 |
if (strstr (password, username) != NULL)
|
| 34 |
verify_ok = 0;
|
| 35 |
for (i = 0; i < pass_len && verify_ok == 1; i++)
|
| 36 |
{
|
| 37 |
ch_repeat[password[i]]++;
|
| 38 |
if (ch_repeat[password[i]] > 2)
|
| 39 |
verify_ok = 0;
|
| 40 |
if (isdigit (password[i]))
|
| 41 |
num_count++;
|
| 42 |
if (isupper (password[i]))
|
| 43 |
upper_case++;
|
| 44 |
if (islower (password[i]))
|
| 45 |
lower_case++;
|
| 46 |
if (num_count > 2)
|
| 47 |
verify_ok = 0;
|
| 48 |
}
|
| 49 |
if (upper_case == 0 || lower_case == 0 || num_count == 0)
|
| 50 |
verify_ok = 0;
|
| 51 |
|
| 52 |
return (verify_ok);
|
| 53 |
}
|