Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SF Coders] Password Generator
#1
[Image: YzwzC.png]

PHP Code:
function GeneratePass($length 5){
$length = (INT)$length//Type cast our variable to be an integer. If anything other than an integer was submitted, it will now equal 0 (With the exception of
                        //the boolean value 'true', which will cause the variable to now equal one.
                        
if ($length <5){ //The minimum length for the password is five, anything less isn't worth the time it takes to process.
$length 5;
}

$alphabet explode(",""a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,1,2,3,4,5,6,7,8,9,0");
$numbers explode(",""1,2,3,4,5,6,7,8,9,0");
$symbols explode(",""!,£,$,%,^,&,*,(,),{,},~,@,:,;,#,?,/,>,.,<");
//Split all the available letters, numbers and symbols up into an array.

$pass ""//Declare our password
while(strlen($pass) < $length){ 
if (
strlen($pass) == ($length -1)){
$choose rand(0, (sizeof($symbols) -1));
$pass .= $symbols[$choose];

}elseif (
strlen($pass) >=($length 3)){
$choose rand(0, (sizeof($numbers) -1));
$pass.= $numbers[$choose];
}else{
$choose rand(0, (sizeof($alphabet) -1));
$pass .= $alphabet[$choose];
}
}
Return 
mysql_real_escape_string(strip_tags($pass));


Above is a function which will generate a password of a given length. A minimum length of 5 is required. The generated password is then sanitised ready for use in a database.
The given password will be in the following format:

[(Given length -3)X A-Z] [2X 0-9] [1 X Symbol]

Example:

PHP Code:
GeneratePassword(15

Output: aAWfUxZyGTeb56%

Usage:
PHP Code:
GeneratePassword(LENGTH
[Image: cooldude.png]

(09-05-2011, 08:36 AM)Orgy Wrote: If you understand what you're doing, you aren't learning anything. ;)
Reply
#2
Great release CoolDude, I think you're going to fit in nicely here at SF Coders.

This was great for your first project.
Reply
#3
(12-05-2011, 03:09 PM)BreShiE Wrote: Great release CoolDude, I think you're going to fit in nicely here at SF Coders.

This was great for your first project.

Thanks. Smile Do you have any suggestions for it?
[Image: cooldude.png]

(09-05-2011, 08:36 AM)Orgy Wrote: If you understand what you're doing, you aren't learning anything. ;)
Reply
#4
(12-05-2011, 03:23 PM)★Cooldude★ Wrote: Thanks. Smile Do you have any suggestions for it?

It's pretty nice and congratulations on your entry into the coders!
[Image: HJzrC.png]
Reply
#5
(12-05-2011, 08:09 PM)Infinity Wrote: It's pretty nice and congratulations on your entry into the coders!

Thank you. Smile
[Image: cooldude.png]

(09-05-2011, 08:36 AM)Orgy Wrote: If you understand what you're doing, you aren't learning anything. ;)
Reply
#6
Haha, It will also be your last Tongue - I kid, It will not be you last.

On-Topic: Great work man, I Like to see projects outside of VB, This was interesting.
"If you cannot explain something simply, then you do not understand it at all." - Albert Einstein
"The best way to predict the future is to invent it." - Alan Kay
Reply
#7
(12-06-2011, 07:26 AM)milopeach Wrote: Haha, It will also be your last Tongue - I kid, It will not be you last.

On-Topic: Great work man, I Like to see projects outside of VB, This was interesting.

:O Nooo. Sad

Thanks. I am actually planning on creating a VB.Net version. Tongue
[Image: cooldude.png]

(09-05-2011, 08:36 AM)Orgy Wrote: If you understand what you're doing, you aren't learning anything. ;)
Reply
#8
PHP Code:
function passgen($len 5){
$alphau = Array ('A','B','C''D''F''G' ,'H''J''K''L''M''N','O''P''Q''R''S','T''U''V''W''X''Y','Z' );
$alphal = array('a','b','c','d','f','g','h','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
$misc = array('1','2','3','4','5','6','7','8','9','[',']','{','}','_','^','%','#','@','+','-');
$list array_merge($alphau,$alphal,$misc);
shuffle($list);
$password '';
for(
$i=0;$i<$len;$i++) {
$add array_rand($list);
$password .=  $list[$add];
}
return 
$password;

Thats my version.
Reply
#9
^That's very interesting, you've introduced me to some new functions. Big Grin
[Image: cooldude.png]

(09-05-2011, 08:36 AM)Orgy Wrote: If you understand what you're doing, you aren't learning anything. ;)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  PHP Dynamic Text Generator TalishHF 5 2,113 01-16-2012, 02:24 PM
Last Post: Gaijin
  How hard would it be to make an signature generator? Extornia 3 1,402 01-11-2012, 08:24 PM
Last Post: Gaijin
  Advanced Random Password Generator zone 2 1,217 11-06-2009, 09:16 PM
Last Post: zone
  mysql display password hey101 2 946 10-16-2009, 04:52 AM
Last Post: hey101

Forum Jump:


Users browsing this thread: 1 Guest(s)