From: sloane@ukans.edu (Bob Sloane)
Subject: Re: npasswd
Date: 26 Jun 2002 08:09:05 CDT [thread overview]
Message-ID: <EQJlsaimkIjn@kuhub.cc.ukans.edu> (raw)
In-Reply-To: 110fcff.0206251503.63ac5cc5@posting.google.com
In article <110fcff.0206251503.63ac5cc5@posting.google.com>,
pdioquino@yahoo.com (Priscilla) writes:
> 2. Are there other tools I've overlooked that can do this?
Take a look at "man prpasswd" in the section on u_policy. When this
is set, the file /tcb/bin/pwpolicy is run to check the password. I
have attached a simple example of how this works. You will probably
want to write something a little more robust for production work. :-)
This just checks to see that the password doesn't equal the username
and that it is mixed case.
--
USmail: Bob Sloane, University of Kansas Computer Center, Lawrence, KS, 66045
E-mail: sloane@ukans.edu http://www.ukans.edu/home/sloane Phone:(785)864-0444
#include <stdio.h>
#include <string.h>
#define UPPERCASE 1
#define LOWERCASE 2
#define NUMERIC 4
#define OTHER 8
main() {
char func[64];
char pass[64];
char user[64];
int ch;
int i;
/*
* first thing should be a function number. Currently, only "1" is defined
*/
if ( fgets(func,63,stdin) == 0 )
exit(0); /* be generous and allow protocol errors */
/*
* Second thing should be the username
*/
if ( fgets(user,63,stdin) == 0 )
exit(0); /* be generous and allow protocol errors */
/*
* delete the trailing newline that fgets appends
*/
if ( user[strlen(user)-1] == '\n' ) user[strlen(user)-1] = '\0';
/*
* next should be the password
*/
if ( fgets(pass,63,stdin) == 0 )
exit(0); /* be generous and allow protocol errors */
/*
* delete the trailing newline that fgets appends
*/
if ( pass[strlen(pass)-1] == '\n' ) pass[strlen(pass)-1] = '\0';
/*
* Don't allow password == username
*/
if ( strcmp(user,pass) == 0 )
exit(1);
/*
* Make sure it isn't all the same case or all numeric
*/
for ( i=ch=0; i < strlen(pass); ++i ) {
if ( pass[i] >= 'a' && pass[i] <= 'z' )
ch |= LOWERCASE;
else if ( pass[i] >= 'A' && pass[i] <= 'Z' )
ch |= UPPERCASE;
else if ( pass[i] >= '0' && pass[i] <= '9' )
ch |= NUMERIC;
else
ch |= OTHER;
}
/*
* if password is all upper case,
*all lower case or all numeric it fails.
*/
if ( ch == LOWERCASE || ch == UPPERCASE || ch == NUMERIC )
exit(1);
/*
* password is OK.
*/
exit(0);
}
next prev parent reply other threads:[~2002-06-26 13:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-06-25 23:03 npasswd Priscilla
2002-06-26 13:09 ` Bob Sloane [this message]
2002-06-26 17:13 ` npasswd Ann Majeske
2002-06-26 21:55 ` npasswd Priscilla
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox