Current location: Hot Scripts Forums » Programming Languages » PHP » password validation


password validation

Reply
  #1 (permalink)  
Old 08-17-04, 03:40 PM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
password validation

im doing a register form where user adds all information.. then im generating a password that is sent to them via email.. i want the password to ALWAYS contain small and BIG letters and numbers.. if not then generate a new password.. the problem is i dont understand the basics of ereg arguments.. this is what i have now:
PHP Code:

function GenerateRandomPassword() {

    
$chars "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    
srand((double)microtime()*1000000);
    
$i 0;
    
$pass '' ;

    while (
$i <= 7) {
        
$num rand() % 62;
        
$tmp substr($chars$num1);
        
$pass $pass $tmp;
        
$i++;
    }
    if (
ereg('[A-Z][a-z][0-9]'$pass)) {
        return 
$pass# password was generated
    
} else {
        echo 
$pass.'<br>'# outputs a valid password 'N8ZOrY3C'
        
return false# but returns false..
    
}

anyone can see that the password is valid.. then sometimes it returns the generated password.. once the valid password looked like this POp0x2zk
so the problem is my ereg() function.. anyone have a solution?
thanks
Wille
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 08-17-04, 04:24 PM
kvnband kvnband is offline
Wannabe Coder
 
Join Date: Jun 2003
Posts: 242
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

Viewing the comments and the random password scripts listed i figured i'd show my simple but effective password generator.


function ranpass($len = "8"){
  $pass = NULL;
  for($i=0; $i<$len; $i++) {
   $char = chr(rand(48,122));
   while (!ereg("[a-zA-Z0-9]", $char)){
     if($char == $lchar) continue;
     $char = chr(rand(48,90));
   }
   $pass .= $char;
   $lchar = $char;
  }
  return $pass;
}

usage:
$password = ranpass(); // Will generate a 8 charater password
$password = ranpass(6); // Will generate a 6 character password

The password will not repeat two characters in a row.
For example you wont recieve like kEg64AA
but you might recieve kEg64Aa.

I tested up to 9999 characters and it went fast even with a number that big. 
That was a comment on php manual for ereg.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 08-18-04, 07:57 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
thanks for the reply.. even if that was not the ansver i was looking for.. always nice to get replys

i would like to go with my own function and i need only fix to this line:
PHP Code:

if (ereg('[A-Z][a-z][0-9]'$pass)) { 

i need it to check that all passwords generated have atleast one number, one small letter and one BIG letter
thanks
Wille
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 08-18-04, 04:04 PM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
did it the hard way..
PHP Code:

if (ereg('[A-Z]'$pass) && ereg('[a-z]'$pass) && ereg('[0-9]'$pass)) { 

shorter ways are still welcome
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
password textbox mpriest HTML/XHTML/XML 14 07-07-04 10:56 AM
password ( ) + MYSQL rsuresh PHP 2 06-15-04 06:42 AM
Quick Question for you php guru's Tokahashi PHP 3 04-09-04 01:00 PM
Searching through a database for a password philkills ASP 1 02-13-04 09:25 PM
Shout Box ( password ) E3ven PHP 2 12-07-03 07:55 AM


All times are GMT -5. The time now is 08:54 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.