How to generate random password using PHP and MySQL

This tutorial concerns how to generate online secure and strong random password via PHP and to mail it to anybody’s email ID when they forgot their password. Also, once the user log in to his/her account using auto-generated password.


        <form method="post"action="generate_password.php">
            <input type="text" name="name" id="name" placeholder="Enter Name">
            <input type="text" name="email" placeholder="Enter Email">
            <input type="submit" name="signup" value="DO SIGNUP">

PHP Code

if (isset($_POST['signup'])) {
    $name   = $_POST['name'];
    $email  = $_POST['email'];
    $chars  = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    $password = substr(str_shuffle($chars), 0, 8);
    mysqli_query($con,"insert into users (name,email,password) values('$name','$email','$password')");
    echo "Your Password Is : " . $password;

Leave a Reply

Your email address will not be published. Required fields are marked *