Code Snippets

  

PHP Source Code


Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 131,911 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,681 people online right now. Registration is fast and FREE... Join Now!





Random Password Generation

A function to generate a random password given the length

Submitted By: Moonbat
Actions:
Rating:
Views: 183

Language: PHP

Last Modified: August 25, 2008

Snippet


  1. <?php
  2. /****************************
  3. * Random Password Generator *
  4. *   Written by Moonbat      *
  5. *     August 25, 2008       *
  6. ****************************/
  7. function GeneratePassword($length) {
  8.         $password = '';
  9.         $string = "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 ! @ # $ % ^ & * ~";
  10.         $chars = explode(" ", $string);
  11.         for ($i=0;$i<=$length;$i++) {
  12.                 $random = rand(0, count($chars));
  13.                 $password .= $chars[$random];
  14.         }
  15.         return $password;
  16. }
  17. ?>

Copy & Paste


Comments


Dark_Nexus 2008-08-27 09:12:59

Take note that this is by no means cryptographically sound and should not be used to generate passwords being used on security-critical systems.


Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month