CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2006
    Posts
    11

    implementing password complexity

    hi can i get help to write code for password complexity?when a user logs in,the code should check for something like this:
    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++;
    }
    the code should also check for a minlen of 6 and maxlen of 12.

    thanks

  2. #2
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

  3. #3
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470

    Re: implementing password complexity

    I think he's looking to check that a password meets minimum criteria - e.g. at least one uppercase char, at least one digit, etc. The code given is a reasonable start - I'd use bools instead of ints, though.
    Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
    --
    Sutter and Alexandrescu, C++ Coding Standards

    Programs must be written for people to read, and only incidentally for machines to execute.

    --
    Harold Abelson and Gerald Jay Sussman

    The cheapest, fastest and most reliable components of a computer system are those that aren't there.
    -- Gordon Bell


  4. #4
    Join Date
    Aug 2004
    Posts
    184

    Re: implementing password complexity

    Also add a check for the length of the password so it meets the length requirements.

    Code:
     
    int pwLen = strlen( pw );
     
    if( pwLen < 6 )
    //password to short
     
    if( pwLen > 12 )
    // password to long
    May want to check the length before checking that the password meets the complexity requirements.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured