How to make a Basic PHP Password Generator

If you are just starting out at learning PHP Language, and want to make a small project then a basic php password generator will be a great starting point.

I’ll show you step by step how you can easily create a password generator using php. You can also customise the code a little bit if you want to test your newly learned skills.

Setting up the PHP File

Okay, so there are three ways that you can create and run a .php file, you can run it on your local server, you can run it on your online server, or you can use an online code editor. There are lots of options so choose whatever is easier for you.

READ MORE – How Robots make our lives easier

You can google or search on youtube for more information.

Creating a String & Running the Basic program

First up let’s create a basic string that will contain all the numbers, alphabets and symbols that we want to have in our generated password.

<?php 

$str=”[email protected]#%&”;

?>

After creating the string you can use shuffle, this will randomly create a string of password on running the php file, and echo will display the password on your screen.

<?php 

$str=”[email protected]#%&”;

$str=str_shuffle($str);

echo $str;

?>

So the above code is a basic php password generator, which will generate a random string of text, number and symbols.

READ – Paycheck records

Setting the Generated Password Length

Now to set the limit on how much length the password should be, you can use substr.

<?php 

$str=”[email protected]#%&”;

$str=str_shuffle($str);

$str=substr($str, 0, 8);

echo $str;

?>

Now what the $str=substr($str, 0, 8);  do is set the limit on how many strings to display after creating the random string. Currently its set to 0 – 8, which you can make anything you want.

So yeah, that is how you can create a very simple php program to generate a random password.