Thursday, September 19, 2013

USER PASSWORD (PART-2)

Example: 1


<?php

session_start();

$username = $_POST['username'];
$password = $_POST['password'];

if($username && $password)
{

$connect = mysql_connect("localhost","root","admin") or die("Couldn't connect!");
mysql_select_db("phplogin") or die("Couldn't find db");

$query= mysql_query("SELECT * From users WHERE  username='$username'");
$numrows = mysql_num_rows($query);

if ($numrows!=0)
{
while ($row = mysql_fetch_assoc($query))
{
$dbusername = $row['username'];
$dbpassword = $row['password'];
}

// check to see if they match
if ($username==$dbusername&&$password==$dbpassword)
{
echo "You are in! <a href='member.php'>Click</a> here to enter the member page.";
$_SESSION['username']=$username;
}
else
echo "Incorrect password!";


}
else
die("That user doesn't exist!");


}
else
  die("Please enter  username and Password!");

?>



Example: 2


member.php


<?php

session_start();

if($_SESSION['username'])
echo "Welcome, " .$_SESSION['username']."!<br><a href='logout.php'>Logout</a><br> <a href='User_Password_Change_Part1.php'>Change password</a>";
else
die ("You must be logged in!");

?>



Example 3


logout.php


<?php

session_start();


session_destroy();

echo "You've been logged out. <a href='User_Login1_2.php'>Click here</a> to return.";

?>



Example 4


<?php

session_start();

$username = $_POST['username'];
$password = $_POST['password'];

if($username && $password)
{

$connect = mysql_connect("localhost","root","admin") or die("Couldn't connect!");
mysql_select_db("phplogin") or die("Couldn't find db");

$query= mysql_query("SELECT * From users WHERE username='$username'");
$numrows = mysql_num_rows($query);

if ($numrows!=0)
{
//code to login
while ($row = mysql_fetch_assoc($query))
{
$dbusername = $row['username'];
$dbpassword = $row['password'];
}
if($username==$dbusername&&$password==$dbpassword)
{
echo "You're in! <a href='member.php'>Click</a> here to enter the member page ";
$_SESSION['username']=$username;
}
else
echo "Incorrect password!";

}
else
die("That user does't exist!");


}
else
   die("Please enter  username and Password!");

?>



Example 5


<?php

session_start();
$user = $_SESSION['username'];

if ($user)
{
//user logged in
echo"
<form action='changepassword.php' method='POST'>
Old password: <input type='text' name='oldpassword'><p>
New password: <input type='password' name='onewpassword'><br>
Repeat New password: <input type='password' name='repeatnewpassword'><p>
<input type='submit' name='submit' value='change password'>
</form>

";
}
else
die("You must be logged in in to change your password");


?>


Example 6


<?php
session_start();
$user = $_SESSION['username'];

if ($user)
{
//user logged in
if ($_POST['submit'])
{
//start changing password
$oldpassword = md5($_POST['oldpassword']);
$newpassword = md5($_POST['newpassword']);
$repeatnewpassword = md5($_POST['repeatnewpassword']);
//check password against db

//connect db
$connect=mysql_connect("localhost", "root", "admin");
mysql_select_db("phplogin") or die();
$queryget = mysql_query("SELECT password FROM users WHERE username='$user' ") or ("Query didnt work");
$row = mysql_fetch_assoc($queryget);

$oldpassworddb = $row['password'];
echo $oldpassworddb."<br>";
echo $oldpassword."<br>";
//check password
if ($oldpassword==$oldpassworddb)

 {
  //check two new password
       if ($newpassword==$repeatnewpassword)
  {
//sucess
echo "Success!";
  }
      //else
die("New password don't match!");
  }

else
die("Old password doesnt match!");

//echo "$oldpassword/$newpassword/$repeatnewpassword";
}
else
{
echo"<form action='' method='POST'>
Old password: <input type='text' name='oldpassword'><p>
New password: <input type='password' name='onewpassword'><br>
Repeat New password: <input type='password' name='repeatnewpassword'><p>
<input type='submit' name='submit' value='change password'>
</form>

";
}
}
else
die("You must be logged in in to change your password");
?>

USER REGISTRATION (PART-3)








Example: 1


register.php

<?php

       echo "<h1> Register</h1>";

$submit = $_POST['submit'];


//form data

$fullname = strip_tags($_POST['fullname']);
$username = strip_tags($_POST['username ']);
$password = md5(strip_tags($_POST['password ']));
$repeatpassword = md5(strip_tags($_POST['repeatpassword ']));
$date = date("y-m-d");


if($submit)

{




}

?>

<html>

<form action='register.php' method='POST'>

<table>
<tr>
<td>Your full name : </td>

<td><input type='text' name='fullname'></td>
</tr>

<tr>
<td>Choose a username :  </td>

<td><input type='text' name='username'></td>
</tr>

<tr>
<td>Choose a password :  </td>

<td><input type='password' name='password'></td>
</tr>

<tr>
<td>Repeat your password :  </td>

<td><input type='password' name='repeatpassword'></td>
</tr>
<p>
<input type='submit' name='submit' value='Register'>


</table>


</form>


</html>






Example: 2


register.php

<?php

       echo "<h1> Register</h1>";

$submit = $_POST['submit'];


//form data

$fullname = strip_tags($_POST['fullname']);
$username = strip_tags($_POST['username ']);
$password = md5(strip_tags($_POST['password ']));
$repeatpassword = md5(strip_tags($_POST['repeatpassword ']));
$date = date("y-m-d");


if($submit)

{

// check for existance

if($fullname && $username && $password && $repeatpassword)

{



}

else

echo"Please fill in <b>all</b> fields!";



}

?>

<html>
<p>

<form action='register.php' method='POST'>

<table>
<tr>
<td>Your full name : </td>

<td><input type='text' name='fullname'></td>
</tr>

<tr>
<td>Choose a username :  </td>

<td><input type='text' name='username'></td>
</tr>

<tr>
<td>Choose a password :  </td>

<td><input type='password' name='password'></td>
</tr>

<tr>
<td>Repeat your password :  </td>

<td><input type='password' name='repeatpassword'></td>
</tr>
<p>
<input type='submit' name='submit' value='Register'>


</table>


</form>


</html>




Example 3


register.php

<?php

       echo "<h1> Register</h1>";

$submit = $_POST['submit'];


//form data

$fullname = strip_tags($_POST['fullname']);
$username = strip_tags($_POST['username ']);
$password = md5(strip_tags($_POST['password ']));
$repeatpassword = md5(strip_tags($_POST['repeatpassword ']));
$date = date("y-m-d");


if($submit)

{

// check for existance

if($fullname && $username && $password && $repeatpassword)

{



}

else

echo"Please fill in <b>all</b> fields!";



}

?>

<html>
<p>

<form action='register.php' method='POST'>

<table>
<tr>
<td>Your full name : </td>

<td><input type='text' name='fullname'></td>
</tr>

<tr>
<td>Choose a username :  </td>

<td><input type='text' name='username'></td>
</tr>

<tr>
<td>Choose a password :  </td>

<td><input type='password' name='password'></td>
</tr>

<tr>
<td>Repeat your password :  </td>

<td><input type='password' name='repeatpassword'></td>
</tr>
<p>
<input type='submit' name='submit' value='Register'>


</table>


</form>


</html>


Example 4


register.php

<?php

       echo "<h1> Register</h1>";

$submit = $_POST['submit'];


//form data

$fullname = strip_tags($_POST['fullname']);
$username = strip_tags($_POST['username ']);
$password = strip_tags($_POST['password ']);
$repeatpassword =strip_tags($_POST['repeatpassword ']);
$date = date("y-m-d");


if($submit)

{

// check for existance

if($fullname && $username && $password && $repeatpassword)

{
//encrypt password
$password = md5($password);
$repeatpassword = md5($repeatpassword);


}

else

echo"Please fill in <b>all</b> fields!";



}

?>

<html>
<p>

<form action='register.php' method='POST'>

<table>
<tr>
<td>Your full name : </td>

<td><input type='text' name='fullname'></td>
</tr>

<tr>
<td>Choose a username :  </td>

<td><input type='text' name='username'></td>
</tr>

<tr>
<td>Choose a password :  </td>

<td><input type='password' name='password'></td>
</tr>

<tr>
<td>Repeat your password :  </td>

<td><input type='password' name='repeatpassword'></td>
</tr>
<p>
<input type='submit' name='submit' value='Register'>


</table>


</form>


</html>



Example 5


register.php

<?php

       echo "<h1> Register</h1>";

$submit = $_POST['submit'];


//form data

$fullname = strip_tags($_POST['fullname']);
$username = strip_tags($_POST['username ']);
$password = strip_tags($_POST['password ']);
$repeatpassword =strip_tags($_POST['repeatpassword ']);
$date = date("y-m-d");


if($submit)

{

// check for existance

if($fullname && $username && $password && $repeatpassword)

{
//encrypt password
$password = md5($password);
$repeatpassword = md5($repeatpassword);

if($password == $repeatpassword)
{


//chech char length of username and fullname
if(strlen($username) >25 || strlen ($fullname)>25)
{
echo "Length of username or fullname is too long!";
}
else
if(strlen($password) >25 || strlen ($password)<6)
{
echo "Password must be between 6 and 25 characters";

}
else

{
//register the user

}



}
else

echo "Your passwords do not match!";



}

else

echo"Please fill in <b>all</b> fields!";



}

?>

<html>
<p>

<form action='register.php' method='POST'>

<table>
<tr>
<td>Your full name : </td>

<td><input type='text' name='fullname'></td>
</tr>

<tr>
<td>Choose a username :  </td>

<td><input type='text' name='username'></td>
</tr>

<tr>
<td>Choose a password :  </td>

<td><input type='password' name='password'></td>
</tr>

<tr>
<td>Repeat your password :  </td>

<td><input type='password' name='repeatpassword'></td>
</tr>
<p>
<input type='submit' name='submit' value='Register'>


</table>


</form>


</html>



USERNAME REGISTRATION (PART -1)

Example: 1


index.php



<html>

<form action='login.php' method='POST'>
Username: <input type='text' name='username'><br>
Password: <input type='password' name='password'><br>
<input type='submit' name='Log in'>
</form><p>

<a href='register.php'> Register? </a>

</html>




Example: 2


register.php


<?php


?>

<html>

<form action='register.php' method='POST'>

<table>
<tr>
<td>Your full name : </td>

<td><input type='text' name='fullname'></td>
</tr>

</table>

</form>


</html>




Example 3


register.php

<?php

       echo "<h1> Register</h1>";
?>

<html>

<form action='register.php' method='POST'>

<table>
<tr>
<td>Your full name : </td>

<td><input type='text' name='fullname'></td>
</tr>

</table>

</form>


</html>



Example 4


register.php

<?php

       echo "<h1> Register</h1>";
?>

<html>

<form action='register.php' method='POST'>

<table>
<tr>
<td>Your full name : </td>

<td><input type='text' name='fullname'></td>
</tr>

<tr>
<td>Choose a username :  </td>

<td><input type='text' name='username'></td>
</tr>

<tr>
<td>Choose a password :  </td>

<td><input type='password' name='password'></td>
</tr>

<tr>
<td>Repeat your password :  </td>

<td><input type='password' name='repeatpassword'></td>
</tr>

</table>



</form>


</html>



Example 5


register.php

<?php

       echo "<h1> Register</h1>";
?>

<html>

<form action='register.php' method='POST'>

<table>
<tr>
<td>Your full name : </td>

<td><input type='text' name='fullname'></td>
</tr>

<tr>
<td>Choose a username :  </td>

<td><input type='text' name='username'></td>
</tr>

<tr>
<td>Choose a password :  </td>

<td><input type='password' name='password'></td>
</tr>

<tr>
<td>Repeat your password :  </td>

<td><input type='password' name='repeatpassword'></td>
</tr>
<p>
<input type='submit' name='submit' value='Register'>


</table>



</form>


</html>






USER REGISTRATION (PART-2)

Example: 1


register.php

<?php

       echo "<h1> Register</h1>";


?>

<html>

<form action='register.php' method='POST'>

<table>
<tr>
<td>Your full name : </td>

<td><input type='text' name='fullname'></td>
</tr>

<tr>
<td>Choose a username :  </td>

<td><input type='text' name='username'></td>
</tr>

<tr>
<td>Choose a password :  </td>

<td><input type='password' name='password'></td>
</tr>

<tr>
<td>Repeat your password :  </td>

<td><input type='password' name='repeatpassword'></td>
</tr>
<p>
<input type='submit' name='submit' value='Register'>


</table>


</form>


</html>



Example: 2


Login.php


<?php

session_start();

$username = $_POST['username'];
$password = $_POST['password'];

if($username && $password)
{

$connect = mysql_connect("localhost","root","admin") or die("Couldn't connect!");
mysql_select_db("phplogin") or die("Couldn't find db");

$query= mysql_query("SELECT * From users WHERE username='$username'");
$numrows = mysql_num_rows($query);

if ($numrows!=0)
{
//code to login
while ($row = mysql_fetch_assoc($query))
{
$dbusername = $row['username'];
$dbpassword = $row['password'];
}
if($username==$dbusername&&$password==$dbpassword)
{
echo "You're in!";
}
else
echo "Incorrect password!";

}
else
die("That user does't exist!");


}
else
    die("Please enter  username and Password!");

?>




Example 3


register.php

<?php

       echo "<h1> Register</h1>";

$submit = $_POST['submit'];


//form data

$fullname = $_POST['fullname'];
$username = $_POST['username '];
$password = $_POST['password '];
$repeatpassword = $_POST['repeatpassword '];

if($submit)

{

echo "$username/$password/$repeatpassword/$fullname";


}

?>

<html>

<form action='register.php' >

<table>
<tr>
<td>Your full name : </td>

<td><input type='text' name='fullname'></td>
</tr>

<tr>
<td>Choose a username :  </td>

<td><input type='text' name='username'></td>
</tr>

<tr>
<td>Choose a password :  </td>

<td><input type='password' name='password'></td>
</tr>

<tr>
<td>Repeat your password :  </td>

<td><input type='password' name='repeatpassword'></td>
</tr>
<p>
<input type='submit' name='submit' value='Register'>


</table>


</form>


</html>



Example 4


register.php

<?php

       echo "<h1> Register</h1>";

$submit = $_POST['submit'];


//form data

$fullname = $_POST['fullname'];
$username = $_POST['username '];
$password = $_POST['password '];
$repeatpassword = $_POST['repeatpassword '];

if($submit)

{

echo "$username/$password/$repeatpassword/$fullname";


}

?>

<html>

<form action='register.php' method='POST'>

<table>
<tr>
<td>Your full name : </td>

<td><input type='text' name='fullname'></td>
</tr>

<tr>
<td>Choose a username :  </td>

<td><input type='text' name='username'></td>
</tr>

<tr>
<td>Choose a password :  </td>

<td><input type='password' name='password'></td>
</tr>

<tr>
<td>Repeat your password :  </td>

<td><input type='password' name='repeatpassword'></td>
</tr>
<p>
<input type='submit' name='submit' value='Register'>


</table>


</form>


</html>



Example 5


register.php

<?php

       echo "<h1> Register</h1>";

$submit = $_POST['submit'];


//form data

$fullname = $_POST['fullname'];
$username = $_POST['username '];
$password = $_POST['password '];
$repeatpassword = $_POST['repeatpassword '];

if($submit)

{

echo md5("alex");


}

?>

<html>

<form action='register.php' method='POST'>

<table>
<tr>
<td>Your full name : </td>

<td><input type='text' name='fullname'></td>
</tr>

<tr>
<td>Choose a username :  </td>

<td><input type='text' name='username'></td>
</tr>

<tr>
<td>Choose a password :  </td>

<td><input type='password' name='password'></td>
</tr>

<tr>
<td>Repeat your password :  </td>

<td><input type='password' name='repeatpassword'></td>
</tr>
<p>
<input type='submit' name='submit' value='Register'>


</table>


</form>


</html>




Example 6


register.php

<?php

       echo "<h1> Register</h1>";

$submit = $_POST['submit'];


//form data

$fullname = $_POST['fullname'];
$username = $_POST['username '];
$password = $_POST['password '];
$repeatpassword = $_POST['repeatpassword '];

echo md5("alex");
if($submit)

{




}

?>

<html>

<form action='register.php' method='POST'>

<table>
<tr>
<td>Your full name : </td>

<td><input type='text' name='fullname'></td>
</tr>

<tr>
<td>Choose a username :  </td>

<td><input type='text' name='username'></td>
</tr>

<tr>
<td>Choose a password :  </td>

<td><input type='password' name='password'></td>
</tr>

<tr>
<td>Repeat your password :  </td>

<td><input type='password' name='repeatpassword'></td>
</tr>
<p>
<input type='submit' name='submit' value='Register'>


</table>


</form>


</html>




Example 7


register.php

<?php

       echo "<h1> Register</h1>";

$submit = $_POST['submit'];


//form data

$fullname = $_POST['fullname'];
$username = $_POST['username '];
$password = md5($_POST['password ']);
$repeatpassword = md5($_POST['repeatpassword ']);


if($submit)

{


echo "$password <br> $repeatpassword ";

}

?>

<html>

<form action='register.php' method='POST'>

<table>
<tr>
<td>Your full name : </td>

<td><input type='text' name='fullname'></td>
</tr>

<tr>
<td>Choose a username :  </td>

<td><input type='text' name='username'></td>
</tr>

<tr>
<td>Choose a password :  </td>

<td><input type='password' name='password'></td>
</tr>

<tr>
<td>Repeat your password :  </td>

<td><input type='password' name='repeatpassword'></td>
</tr>
<p>
<input type='submit' name='submit' value='Register'>


</table>


</form>


</html>



Example 8


register.php

<?php

       echo "<h1> Register</h1>";

$submit = $_POST['submit'];


//form data

$fullname = strip_tags($_POST['fullname']);
$username = strip_tags($_POST['username ']);
$password = md5(strip_tags($_POST['password ']));
$repeatpassword = md5(strip_tags($_POST['repeatpassword ']));


if($submit)

{


echo "$password <br> $repeatpassword ";

}

?>

<html>

<form action='register.php' method='POST'>

<table>
<tr>
<td>Your full name : </td>

<td><input type='text' name='fullname'></td>
</tr>

<tr>
<td>Choose a username :  </td>

<td><input type='text' name='username'></td>
</tr>

<tr>
<td>Choose a password :  </td>

<td><input type='password' name='password'></td>
</tr>

<tr>
<td>Repeat your password :  </td>

<td><input type='password' name='repeatpassword'></td>
</tr>
<p>
<input type='submit' name='submit' value='Register'>


</table>


</form>


</html>



Example 9


register.php

<?php

       echo "<h1> Register</h1>";

$submit = $_POST['submit'];


//form data

$fullname = strip_tags($_POST['fullname']);
$username = strip_tags($_POST['username ']);
$password = md5(strip_tags($_POST['password ']));
$repeatpassword = md5(strip_tags($_POST['repeatpassword ']));


if($submit)

{


echo $username. "<br>".$fullname;

}

?>

<html>

<form action='register.php' method='POST'>

<table>
<tr>
<td>Your full name : </td>

<td><input type='text' name='fullname'></td>
</tr>

<tr>
<td>Choose a username :  </td>

<td><input type='text' name='username'></td>
</tr>

<tr>
<td>Choose a password :  </td>

<td><input type='password' name='password'></td>
</tr>

<tr>
<td>Repeat your password :  </td>

<td><input type='password' name='repeatpassword'></td>
</tr>
<p>
<input type='submit' name='submit' value='Register'>


</table>


</form>


</html>