Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
09-12-2006, 02:05 AM
|
#1
|
LQ Newbie
Registered: Sep 2006
Posts: 14
Rep:
|
password complexity
hi.can password complexity be implemented programmatically as an application.can u help me with some source code?thanks
|
|
|
09-12-2006, 03:58 AM
|
#2
|
Moderator
Registered: May 2001
Posts: 29,415
|
Hello there and welcome to LQ. Hope you like it here.
Could have a look at the source of Openwall's pam_passwdqc (yes, that's *two* terms to search with) (with emphasis on search). BTW, taxonomically this is not a question about security but programming. I'll move this thread to the programming forum.
|
|
|
09-12-2006, 04:45 AM
|
#3
|
Senior Member
Registered: Mar 2003
Location: Brisbane Queensland Australia
Distribution: Custom Debian Live ISO's
Posts: 1,291
Rep:
|
Hi and welcome,
Not quite sure if this is what your after. Are you after something to generate a complex password? something like this.
Code:
head -c 15 /dev/random | uuencode -m - | head -2 | tail -1
Last edited by fotoguy; 09-12-2006 at 04:51 AM.
|
|
|
09-12-2006, 05:34 AM
|
#4
|
Senior Member
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,797
|
Please define what complexity you want?
The code snippet below is what I use (in combination with a length check) to verify if a user has specified/generated a strong password.
Code:
if(!(ereg("[A-Z]",$data['password']) &&
ereg("[a-z]",$data['password']) &&
ereg("[0-9]",$data['password']) &&
ereg("[^A-Za-z0-9]",$data['password'])))
{
$msg="<P class=\"db_error\">Weak password</P>";
return -1;
}
Last edited by Wim Sturkenboom; 09-12-2006 at 05:58 AM.
|
|
|
09-12-2006, 06:29 AM
|
#5
|
LQ Newbie
Registered: Sep 2006
Posts: 14
Original Poster
Rep:
|
thank u sir.but how can this be used along with a length check?initially i was told to set minlen= in /etc/pam.d to whichever value to set password length.is there any other way.also in the code given above what is 'password'?
|
|
|
09-12-2006, 10:10 PM
|
#6
|
Senior Member
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,797
|
Your initial question was not quite complete and clear, I guess. I thought that you needed a program that could check password complexity. The given code snippet does that. It's php code that I use in a web application and verifies if the given password (read from a html field) contains at least one uppercase character, one lowercase character, one digit and one other character before it will be stored in a database.
I don't know about pam, others can maybe help there.
Last edited by Wim Sturkenboom; 09-12-2006 at 10:12 PM.
|
|
|
09-13-2006, 12:42 AM
|
#7
|
LQ Newbie
Registered: Sep 2006
Posts: 14
Original Poster
Rep:
|
thank u sir.yes,i wanted to check for the same conditions.but the code u have give i don't understand.can u give me a C program which describes the same?thank u
|
|
|
09-13-2006, 12:57 AM
|
#8
|
LQ Guru
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507
Rep: 
|
This (not so nice) c code should do the trick:
Code:
int checkpw(char *pw){
// Input: null-terminated password string
// Output: 0 for good password, non-zero for bad
// Does NOT check length
// Requires 1+ upper, 1+ lower, 1+ numeric
int lc=0,uc=0,num=0;
while(*pw){
if( *pw => 'A' && *pw <= 'Z' )
uc=1;
else if( *pw >= 'a' && *pw <= 'z' )
lc=1;
else if( *pw >= '0' && *pw <= '9' )
num=1;
pw++;
}
return 3-(uc+lc+num);
}
|
|
|
09-13-2006, 07:09 AM
|
#9
|
Senior Member
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,797
|
OK, so it must be C. Have a look at Matir's code. Just add a check for characters that are outside A..Z, a..z, 0..9 to make it identical to my php example.
|
|
|
09-13-2006, 09:49 AM
|
#10
|
LQ Guru
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507
Rep: 
|
Adding the check for other characters would be fairly simple:
Code:
int checkpw(char *pw){
// Input: null-terminated password string
// Output: 0 for good password, non-zero for bad
// Does NOT check length
// Requires 1+ upper, 1+ lower, 1+ numeric
int lc=0,uc=0,num=0,non=0;
while(*pw){
if( *pw => 'A' && *pw <= 'Z' )
uc=1;
else if( *pw >= 'a' && *pw <= 'z' )
lc=1;
else if( *pw >= '0' && *pw <= '9' )
num=1;
else
non=1;
pw++;
}
return 4-(uc+lc+num+non);
}
|
|
|
09-13-2006, 10:28 PM
|
#11
|
Senior Member
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,797
|
Quote:
Originally Posted by Matir
Adding the check for other characters would be fairly simple:
|
I know, but nobody ever died of doing some thinking himself.
|
|
|
09-13-2006, 10:53 PM
|
#12
|
LQ Guru
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507
Rep: 
|
Eh true. I'd definitely not require that, but it depends on the level of complexity you want to enforce.
|
|
|
All times are GMT -5. The time now is 12:35 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|