LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 09-12-2006, 02:05 AM   #1
moinpasha
LQ Newbie
 
Registered: Sep 2006
Posts: 14

Rep: Reputation: 0
password complexity


hi.can password complexity be implemented programmatically as an application.can u help me with some source code?thanks
 
Old 09-12-2006, 03:58 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608Reputation: 3608
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.
 
Old 09-12-2006, 04:45 AM   #3
fotoguy
Senior Member
 
Registered: Mar 2003
Location: Brisbane Queensland Australia
Distribution: Custom Debian Live ISO's
Posts: 1,291

Rep: Reputation: 62
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.
 
Old 09-12-2006, 05:34 AM   #4
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,797

Rep: Reputation: 282Reputation: 282Reputation: 282
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.
 
Old 09-12-2006, 06:29 AM   #5
moinpasha
LQ Newbie
 
Registered: Sep 2006
Posts: 14

Original Poster
Rep: Reputation: 0
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'?
 
Old 09-12-2006, 10:10 PM   #6
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,797

Rep: Reputation: 282Reputation: 282Reputation: 282
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.
 
Old 09-13-2006, 12:42 AM   #7
moinpasha
LQ Newbie
 
Registered: Sep 2006
Posts: 14

Original Poster
Rep: Reputation: 0
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
 
Old 09-13-2006, 12:57 AM   #8
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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);
}
 
Old 09-13-2006, 07:09 AM   #9
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,797

Rep: Reputation: 282Reputation: 282Reputation: 282
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.
 
Old 09-13-2006, 09:49 AM   #10
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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);
}
 
Old 09-13-2006, 10:28 PM   #11
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,797

Rep: Reputation: 282Reputation: 282Reputation: 282
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.
 
Old 09-13-2006, 10:53 PM   #12
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Eh true. I'd definitely not require that, but it depends on the level of complexity you want to enforce.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Algorithmic Complexity + Asymptotic Notations koodoo Programming 1 09-02-2006 12:55 PM
Setting password complexity Harry Seldon Linux - General 1 08-04-2006 02:33 PM
Jgrasp install complexity techlogic Linux - Software 8 02-07-2006 02:33 PM
Howto change system password policies (passwd length, complexity) tisource Linux - Security 3 09-06-2005 12:01 AM
Linux PAM minimum password and complexity reemo73 Linux - Software 3 06-01-2005 03:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 12:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration