Sunday 26 August 2012

PHP script for password encryption

// siddhu vydyabhushana // Leave a Comment
hi friends i explained and teach u about php in many posts but now i want teach u on topic password encryption. on registration page our password going to be stored in one particular location in our database.
last post relate to this is

in facebook,google they protected their password by using this method

   


                                                         DOWNLOAD ALL IN ONE FILE 

1.At first you need to create a table with three coloumns
        id must be tick auto increment,username,passcode

2. Databse connection db.php




<?php
mysql_connect("localhost","root","") or die("Opps some thing went wrong");
mysql_select_db("dream") or die("Opps some thing went wrong");
?>

3.Registration page

<?php
include("db.php");
if($_SERVER["REQUEST_METHOD"] == "POST")
{
// username and password sent from Form
$username=$_POST['username'];
$password=$_POST['password'];
$password=md5($password); // Encrypted Password
$sql="Insert into admin(username,passcode) values('$username','$password');";
$result=mysql_query($sql);
echo "Registration Successfully";
}
?>
<html>
<body>
<form action="registration.php" method="post">
<label>UserName :</label>
<input type="text" name="username"/><br />


<label>Password :</label>
<input type="password" name="password"/><br/>
<input type="submit" value=" Registration "/><br />
</form>
</body>
</html>

4.Login page

<?php
include("db.php");
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST")
{
// aitamelearning.blogspot.com
$username=$_POST['username'];
$password=$_POST['password'];
$password=md5($password); // Encrypted Password
$sql="SELECT id FROM admin WHERE username='$username' and passcode='$password'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);


if($count==1)
{
header("location: welcome.php");//its ur wish
}
else
{
$error="Your Login Name or Password is invalid";
}
}
?>
<form action="login.php" method="post">
<label>UserName :</label>
<input type="text" name="username"/><br />
<label>Password :</label>
<input type="password" name="password"/><br/>
<input type="submit" value=" Login "/><br />
</form>

0 comments:

Post a Comment