PHP Random Password Generator using Jquery AJAX
Hi friends in this lesson we will learn how to generate random password with md5 encryption..just follow the below example how to generate random password in php.
PHP Random Password Generator |
CREATE TABLE IF NOT EXISTS `user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(50) NOT NULL, `password` varchar(20) NOT NULL, `encryptpass` varchar(100) NOT NULL, `email` varchar(50) NOT NULL, PRIMARY KEY(id) ) ENGINE=MyISAM AUTO_INCREMENT=19 DEFAULT CHARSET=latin1;
Files Structure:
Create 3 files and copy paste the below codes..
1. index.html
2. script.js
3. signup.php
1. index.html
<html> <head> <title>AJAX Random Password Generator using PHP MySQL</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script type="text/javascript" src="script.js"></script> </head> <h2>AJAX Random PassWord Generator</h2> <form method="POST" action=""> <table> <tr> <td>Email</td> <td><input type="text" id="email"/></td> </tr> <tr> <td>UserName</td> <td><input type="text" id="username"/></td> </tr> <tr> <td></td> <td><input type="button" id="submit" value="Sign Up"/><br/> </td> </tr> </table> </form> <div id="success"></div> </html>
2. script.js
$(document).ready(function(){ $("#submit").click(function(){ var email=$("#email").val(); var username=$("#username").val(); if(email==""||username==""){ $('#success').html('Both Fileds are Mandatory'); return false; }else{ $.ajax({ url:"signup.php", type:"POST", data:{username:username,email:email}, success:function(data){ $("#success").html(data); } }); return false; } }); });
3. signup.php
<?php $conn=new mysqli('localhost','root','','codenair'); if(!empty($_POST['email'])&&!empty($_POST['username'])){ $username=$_POST['username']; $email=$_POST['email']; //Checking for Email Availablity if(!empty($email)){ $result=mysqli_query($conn,"SELECT*FROM user WHERE email='$email'"); $count=$result->num_rows; if($count==0){ $ok=''; }else{ echo 'Email Already Exist'; } } //Generating Random PASS if(isset($ok)){ $password = $username.mt_rand(444,10000); //PHP Password encryption $encryptpassword=md5($password); $result=mysqli_query($conn,"INSERT INTO user(username,password,encryptpass,email)VALUES('$username','$password','$encryptpassword','$email')"); if($result){ echo "Your Registration Successfull.Your PassWord is:<font color=green><b>$password</b></font>"; }else{ echo "Sorry Failed to Registration.Try Again"; } } }else{ echo 'Your Username or Email Empty'; } ?>
That's it Friends how to Generate Random Password using PHP with MD5 encryption..
Keep Visiting ...
also learn..
1. Generate Unique Username in PHP MYSQL
2. Validate Email in PHP
3. PHP array to String and String Array
4. how to encrypt password in php
No comments:
Post a Comment
Thank You for Your Comment
Note: Only a member of this blog may post a comment.