PHP Simple password generator
Posted on: April 14, 2006 at 12:00 AM
The simplest password generator described here uses one cycle to concatenate random characters into the random sized string.

PHP Simple password generator

In this tutorial I will be showing you how to create a random password using nothing but loops and random letters. For extra security I will define a minimum length and a maximum length, I will also make it so you can't define a password from using the url.

First we need to define everything. This includes the min length, max length and emptying the password:

$min=4;
$max=15;
$pwd="";


Now we need to start the loop of creating it, using the $min and $max we can get a random length:

for($i=0;$i<rand($min,$max);$i++)

We need to get a load of letters now, but we have to be sure there are valid letters and not other characters:

$num=rand(48,122);
if(($num > 97 && $num < 122))
{
    $pwd.=chr($num);
}

else if(($num > 65 && $num < 90))
{
    $pwd.=chr($num);
}

else if(($num >48 && $num < 57))
{
    $pwd.=chr($num);
}

else if($num==95)
{
    $pwd.=chr($num);
}

Just a load of checking, nothing much really there. Because this is a tutorial, we would output the result of our password:

echo $pwd;

Be carefull about including that line for the final script. If you are emailing the password then you don't need it, you decide.

The complete code is here:

<?php
// filename "pword.php"


$min=4; // minimum length of password
$max=15; // maximum length of password
$pwd=""; // to store generated password

for($i=0;$i<rand($min,$max);$i++)
{
$num=rand(48,122);

  if(($num > 97 && $num < 122))
  {
      $pwd.=chr($num);
  }

  else if(($num > 65 && $num < 90))
  {
      $pwd.=chr($num);
  }

  else if(($num >48 && $num < 57))
  {
      $pwd.=chr($num);
  }

  else if($num==95)
  {
      $pwd.=chr($num);
  }

  else
  {
      $i--;
  }
}

echo $pwd; // prints the password
?>


More Tutorials on roseindia.net for the topic PHP Simple password generator.
ModuleNotFoundError: No module named 'simple_password_generator'
ModuleNotFoundError: No module named 'simple_password_generator'  Hi...: No module named 'simple_password_generator' How to remove the ModuleNotFoundError: No module named 'simple_password_generator' error? Thanks  
 
ModuleNotFoundError: No module named 'password-generator'
ModuleNotFoundError: No module named 'password-generator'  Hi, My... named 'password-generator' How to remove the ModuleNotFoundError: No module named 'password-generator' error? Thanks   Hi, In your
 
encrypt the username and password using PHP
encrypt the username and password using PHP  How can we encrypt the username and password using PHP?   Hi friends, You can use the MySQL PASSWORD() function to encrypt username and password. For example, INSERT
 
php
Write a simple PHP program that display the days of week as per the system date using switch case statement.  Write a simple PHP program that display the days of week as per the system date using switch case statement
 
ModuleNotFoundError: No module named 'ca-password-generator'
ModuleNotFoundError: No module named 'ca-password-generator'  Hi...: No module named 'ca-password-generator' How to remove the ModuleNotFoundError: No module named 'ca-password-generator' error? Thanks   Hi
 
ModuleNotFoundError: No module named 'ca-password-generator'
ModuleNotFoundError: No module named 'ca-password-generator'  Hi...: No module named 'ca-password-generator' How to remove the ModuleNotFoundError: No module named 'ca-password-generator' error? Thanks   Hi
 
ModuleNotFoundError: No module named 'password-generator-gtk'
ModuleNotFoundError: No module named 'password-generator-gtk'  Hi...: No module named 'password-generator-gtk' How to remove the ModuleNotFoundError: No module named 'password-generator-gtk' error? Thanks   Hi
 
ModuleNotFoundError: No module named 'python-password-generator'
ModuleNotFoundError: No module named 'python-password-generator'  Hi...: No module named 'python-password-generator' How to remove the ModuleNotFoundError: No module named 'python-password-generator' error? Thanks  
 
ModuleNotFoundError: No module named 'python-password-generator'
ModuleNotFoundError: No module named 'python-password-generator'  Hi...: No module named 'python-password-generator' How to remove the ModuleNotFoundError: No module named 'python-password-generator' error? Thanks  
 
ModuleNotFoundError: No module named 'random-password-generator'
ModuleNotFoundError: No module named 'random-password-generator'  Hi...: No module named 'random-password-generator' How to remove the ModuleNotFoundError: No module named 'random-password-generator' error? Thanks  
 
ModuleNotFoundError: No module named 'random-password-generator-cli'
ModuleNotFoundError: No module named 'random-password-generator-cli'  ...: No module named 'random-password-generator-cli' How to remove the ModuleNotFoundError: No module named 'random-password-generator-cli' error
 
php
php  im beginner to php. i faced problem with creating form and data stored into mysql <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01...; <td><input type="Password" name="pwd" size="20">
 
php
php  im beginner to php. i faced problem with creating form and data stored into mysql <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01...; <td><input type="Password" name="pwd" size="20">
 
PHP
is valid and uses the correct password. If the user is not in the database, then the user should be prompted to register the username and password, and then allowed to use the username and the password to access the system (Main Menu
 
sql php array
sql php array       SQL PHP Array support simple dimension array. The SQL PHP Array is used... illustrate an example from 'SQL PHP Array'. To understand and grasp
 
forget password?
forget password?  can anyone help me? how to create a module of forget password?the password can reset by generate random password and send to user's email..i develop the php system using xampp and dreamweaver
 
forget password?
forget password?  can anyone help me? how to create a module of forget password?the password can reset by generate random password and send to user's email..i develop the php system using xampp and dreamweaver
 
Simple Java applet that need usernam, password and textfield.
Simple Java applet that need usernam, password and textfield.  Hi. Anyone can help me on this matter: I need to create a small application that require user to login by username and password. After login, they should meet
 
ModuleNotFoundError: No module named 'simple_test_generator'
ModuleNotFoundError: No module named 'simple_test_generator'  Hi...: No module named 'simple_test_generator' How to remove the ModuleNotFoundError: No module named 'simple_test_generator' error? Thanks   Hi
 
New features in PHP 5.5
available in PHP 5.5 Here is the syntax of using the the password hashing API... the password using following code: password_verify($password, $hash); 4. In PHP 5.5... Starting PHP Learn the basics of PHP with this quick and simple tutorial
 
php java
php java  why PHP is becoming more popular than java   PHP is more popular than Java because of following reasons: 1)PHP web hosting options are superior. 2)PHP provides rapid development and instant gratification
 
PHP MySQL Connect to a Database
' (using password: NO) in C:\wamp\www\php\dbConn.php on line 2 error NOTE... PHP MySQL Connect to a Database:       In WAMP software stack, php and mysql are bundled together and we can use
 
Data Generator
JavaScript, PHP and MySQL. Characteristics Data generator is browser... Data Generator Data Generator is free open source script that is designed to create the application, which can be used to generate a large sum of data
 
Javascript and PHP
Javascript and PHP  Hello, I want to know how to call javascript function inside PHP code . Could you please tell me the way to call it? Thanks   Here is a simple example of php that calls javascript function. <
 
PHP Question
PHP Question  I am trying to make php Readline where it reads from.... { > fclose($handle); // Close the file. } > $password=readLine("/home/users/".$username.".txt", > 1); if ($password==$_POST['oldpass']) >
 
PHP Question
PHP Question  I am trying to make php Readline where it reads from.... { > fclose($handle); // Close the file. } > $password=readLine("/home/users/".$username.".txt", > 1); if ($password==$_POST['oldpass']) >
 
writing webservices in php
writing webservices in php  How to write a simple web service in PHP
 
PHP Array
to stored values in key value pair. Here is simple example of PHP array: $fruit...PHP Array In this page we will learn about PHP Array. We will also understand how to use PHP Array in your PHP program. The PHP Array is very useful
 
PHP ini
PHP ini       PHP provides us so... customize the behavior of php. Using this file maintaining PHP will be as easy... can configure all PHP's runtime configurations. It is also better
 
Password
Password  make a program which ask ask the username and password * in this format. in C language
 
ile_exists php
ile_exists php  i have written a simple php code where i used the file_exists. But somehow it's not working. Please suggest Thanks
 
simple code to write an read and write the login detail to a xml file using javascript ( username and password )
simple code to write an read and write the login detail to a xml file using javascript ( username and password )  pls can nyone give me a code to write and read the login details (username and password )into a xml file using
 
php mysql web application tutorial
php mysql web application tutorial  How to create a simple php mysql web application? Please post an example or tutorial
 
simple eg
simple eg   <?php</li> $string = ?Hello Users?; print (?Welcome to Roseindia, I want to greet $string?); print (??); $string = ?Bye Bye!?; print (?OK meet you soon, $string?); ?> in this program we get a error at line
 
PHP 5.4.23 Features
PHP is the most popular open source, rich featured and high level web... servers. The PHP (Hypertext Preprocessor) scripting language is widely used by developers for creating complex and high level web applications. PHP has rich
 
connection of php to MySQL.
connection of php to MySQL.  I have a query on connection of php... of MySQL) for Database I have a page admin.php <?php if (isset($_POST...']; $password=$_POST['password']; $sqlinsert="INSERT INTO adminlogin (username
 
php
php   what is php   PHP Tutorials
 
php
php  what is php
 
php
php using javasript  how to set timer in php using javasript
 
SQL PHP
SQL PHP       PHP is a server side scripting language. To access the data in PHP,you must create a connection to the database. The PHP server side script
 
php
php  i want to know about php and php plateform required software to make php program and database that used in php program?   Please visit the following link: PHP database
 
php
php  i want to know about php and php plateform required software to make php program and database that used in php program?   Please visit the following link: PHP database
 
creating a global variable with php
below.. function processlogin($username, $password){     global $database;     $database->login($username, $password
 
PHP Sticky form problem
PHP Sticky form problem  I have done the full coding of a sticky form. It is a simple calculator. Whenever I input the value and press "add" or"minus... it need me to done to solve it. <html> <head> <title>Simple
 
PHP Sticky form problem
PHP Sticky form problem  I have done the full coding of a sticky form. It is a simple calculator. Whenever I input the value and press "add" or"minus... it need me to done to solve it. <html> <head> <title>Simple
 
php
php  show the constructor overloading in php
 
PHP
PHP  How to work in drupal with PHP
 
SQL PHP Where
the example we use PHP server side script that include host, user, password...; <?php $host = "localhost"; $user = "root"; $password... SQL PHP Where      
 
PHP Error handling
; (using password: NO) in C:\wamp\www\php\temp.php on line 2 Now we will examine...PHP Error handling: PHP provides so many techniques to handle error, if error...: Example: <?php $var=mysql_connect("localhost","
 
PHP SQL close connection
PHP SQL close connection       PHP SQL close connection is used to close a connection between the PHP... 'PHP SQL close Connection'. To understand and grasp the example we include
 
Ads

Related Tags for PHP Simple password generator:


Ads

 
Advertisement null

Ads