brown2005 Posted October 3, 2006 Share Posted October 3, 2006 Hi is this the best function for a Random Password or is there a better one...function makeRandomPassword() { $salt = "abchefghjkmnpqrstuvwxyz0123456789"; srand((double)microtime()*1000000); $i = 0; while ($i <= 7){ $num = rand() % 33; $tmp = substr($salt, $num, 1); $pass = $pass . $tmp; $i++;}$pass = md5($pass); return $pass; } Quote Link to comment https://forums.phpfreaks.com/topic/22881-random-password/ Share on other sites More sharing options...
pedrobcabral Posted October 3, 2006 Share Posted October 3, 2006 If you want security (md5) you could also add the CAPITAL LETTERS. Quote Link to comment https://forums.phpfreaks.com/topic/22881-random-password/#findComment-103111 Share on other sites More sharing options...
brown2005 Posted October 3, 2006 Author Share Posted October 3, 2006 wat in the salt bit...? Quote Link to comment https://forums.phpfreaks.com/topic/22881-random-password/#findComment-103113 Share on other sites More sharing options...
paul2463 Posted October 3, 2006 Share Posted October 3, 2006 yes in the $salt bit[code] $salt = "abchefghjkmnpqrstuvwxyzABCHEFGHJKMNPQRSTUVWXYZ0123456789";[/CODE]and change the first $num line to[code]$num = rand() % 56;[/code] Quote Link to comment https://forums.phpfreaks.com/topic/22881-random-password/#findComment-103155 Share on other sites More sharing options...
Daniel0 Posted October 3, 2006 Share Posted October 3, 2006 [quote author=paul2463 link=topic=110380.msg446088#msg446088 date=1159892641]and change the first $num line to[code]$num = rand() % 56;[/code][/quote]What would that help? Quote Link to comment https://forums.phpfreaks.com/topic/22881-random-password/#findComment-103248 Share on other sites More sharing options...
paul2463 Posted October 3, 2006 Share Posted October 3, 2006 sorry that was me misunderstanding the function, i thought it was the maximum number required whilst working over $salt, which is about 33 characters long, and putting the extra capitals in makes it 54....having checked it doesnt matter. Quote Link to comment https://forums.phpfreaks.com/topic/22881-random-password/#findComment-103274 Share on other sites More sharing options...
Daniel0 Posted October 3, 2006 Share Posted October 3, 2006 An easy version could be: [code]<?phpfunction random_password($length=8){ return substr(md5(microtime()),0,$length);}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/22881-random-password/#findComment-103278 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.