AZForums: Random Number Password Generator - AZForums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Random Number Password Generator

#1 User is offline   cipcip Icon

  • AZ Mastermind
  • PipPipPipPipPipPipPipPipPip
  • View blog
Group:
Members
Posts:
2,624
Joined:
19-November 06

Posted 12 April 2007 - 07:35 AM

Code:

<?php 

$charset = array('0','1','2','3','4','5','6','7','8','9','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',',','.','/','<','>','?',';',':','[',']','{','}','|','!','@','#','&','%','^','*','(',')','-','=','_','+','~'); 
// A huge array of characters that will be in the password, items can be added and removed at will 

$size = sizeof($charset) - 1; // Get the number of items in the array 

$password = ""; // To stop possible xss injection 
for($i = 0, $i < 8, $i++) 
{ 
$password .= $charset[rand(0, $size)]; // Grab a random character 
} 
echo "<b>Random Password:</b> $password"; // Output the password 

?>


Enjoy! >.<
0

#2 User is offline   Rokan Icon

  • AZ Guru
  • PipPipPipPipPipPipPipPipPipPip
  • View blog
Group:
+ Legendary
Posts:
6,657
Joined:
29-August 05

Posted 12 April 2007 - 09:25 AM

Very nice CipCip. Didn't know you were a ?PHP man. :D
0

#3 User is offline   cipcip Icon

  • AZ Mastermind
  • PipPipPipPipPipPipPipPipPip
  • View blog
Group:
Members
Posts:
2,624
Joined:
19-November 06

Posted 12 April 2007 - 11:43 AM

i am learning ... this is what i have learned to do so far :P
0

#4 User is offline   Oosband Icon

  • DnB Oos
  • PipPipPipPipPipPipPipPipPipPip
  • View blog
Group:
+ Legendary
Posts:
5,527
Joined:
30-August 05
Location:
UK

Posted 19 April 2007 - 09:41 PM

Nice man. I've made one and I think another member did too, so take a look at them also and see what's different. You might learn a little more on this subject. Great script though.
0

#5 User is online   Kobius Icon

  • «• 千と千尋の神隠し •»
  • PipPipPipPipPipPipPipPipPipPipPipPip
  • View blog
Group:
Administrator
Posts:
15,610
Joined:
25-August 05

Posted 27 April 2007 - 10:20 AM

Wow, that is really clever stuff cipcip. Great job.


Accepted and moved to Web tutorials!
Posted Image
0

#6 User is offline   Rokan Icon

  • AZ Guru
  • PipPipPipPipPipPipPipPipPipPip
  • View blog
Group:
+ Legendary
Posts:
6,657
Joined:
29-August 05

Posted 10 May 2007 - 02:45 PM

I made a slight improvement so that you can choose the amount of characters you want the password to use.
<?php
if(isset($_POST['value'])){
$charset = array('0','1','2','3','4','5','6','7','8','9','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');
// A huge array of characters that will be in the password, items can be added and removed at will

$size = sizeof($charset) - 1; // Get the number of items in the array
$password = ""; // To stop possible xss injection

for($i = 0; $i < $_POST['value']; $i++)
{
$password .= $charset[rand(0, $size)]; // Grab a random character
}
echo "<b>Random Password:</b> $password"; // Output the password
} else { ?>
<form method='post' action="<?=basename($_SERVER['PHP_SELF'])?>">
Number of letters<br/>
<select multiple name='value' size='4'>
<option value='5'>5</option>
<option value='10'>10</option>
<option value='15'>15</option>
</select><br/>
<input type='submit' value='Randomize'>
</form>
<?
}
?>


I get bored sometimes.

Hopefully cipcip sees this.
0

#7 User is offline   cipcip Icon

  • AZ Mastermind
  • PipPipPipPipPipPipPipPipPip
  • View blog
Group:
Members
Posts:
2,624
Joined:
19-November 06

Posted 11 May 2007 - 04:34 PM

thanks for the update ... :)
0

#8 User is offline   Rokan Icon

  • AZ Guru
  • PipPipPipPipPipPipPipPipPipPip
  • View blog
Group:
+ Legendary
Posts:
6,657
Joined:
29-August 05

Posted 11 May 2007 - 07:42 PM

;)

Your welcome.
I have an even better update for this almost done. XD
0

#9 User is offline   Shevliaskovic Icon

  • i just shat into my pants.Can i get into yours?
  • PipPipPipPipPipPipPipPipPipPip
  • View blog
Group:
+ Legendary
Posts:
5,319
Joined:
17-May 07

Posted 18 May 2007 - 11:03 AM

nice one ;)



Formerly Known as : Nick the Greek

Έχεις στα χείλη σου λίγο σπέρμα και ο μπαμπάς σου έχει ξεκούμπωτο το φερμοάρ

☻/
/▌
/ \
0

#10 User is offline   anima Icon

  • e^x is my friend
  • PipPipPipPipPipPip
  • View blog
Group:
Members
Posts:
493
Joined:
28-May 07

Posted 30 May 2007 - 04:07 PM

I made a sleekier version of it, instead of using an array, I'm using ASCII ranges.

Quote

<?
function randomstring($num) {
$string = ""; // For strict webservers
for($i = 0; $i < $num; $i++) {
$string .= (rand(0,1) == 1) ? strtoupper(chr(rand(97,122))) : chr(rand(97,122));
}
return $string;
}
?>

If you want to change which characters can be used (in the example, I've restricted to small-case alphanumeric, but the second random decides whether it'd be upped or not), change the ranges in this one:

Quote

<?
function randomstring($num) {
for($i = 0; $i < $num; $i++) {
$string .= chr(rand(97,122));
}
return $string;
}
?>


And for those who are not familiar with ASCII:
97-122: lowercase (abcdefghijklmnopqrstuvwxyz)
48-57: numbers (0123456789)
58-64: non-standard characters (<>:;=?@)
33-47: Punctuation and marks (#%!&/+_*'".)
65-90: uppercase
90-97: non-standard characters ([]^_`)

If you want to include all of them, use 33-122.
Gone.
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users