Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function checkAccount($username, $password){
- include("INC/dbconnect.inc");/*"INC/dbconnect.inc" is <?php $pdo = new PDO("mysql:host=localhost;dbname=socialnetwork","user","123"); ?>*/
- $select = $pdo->prepare("SELECT id,password FROM users WHERE user_username = :username");
- $select->execute(array(':username'=>$username));
- $q_rows = $select->fetchAll();
- if($q_rows[0][0]/*the ID of the user, it should always be greater than 1, if not then the username does not exist*/ > 0 && $q_rows[0][0] != null){
- if($q_rows[0][1]/*the password of the user*/ == $password)
- return "true";
- else
- return "false";
- }
- else
- return "false";
- $pdo=null;
- }
- if(isset($_POST["submit"])){
- $userData = array();
- $userData[0] = $_POST['username'];
- $userData[1] = hash("sha512", $_POST['password']);
- if(checkAccount($userData[0], $userData[1])){
- echo "<div class=\"formconfirm\">
- <table border=\"0\">
- <tr>
- <td>
- <img src=\"http://cdn1.iconfinder.com/data/icons/onebit/PNG/onebit_34.png\" />
- </td>
- <td>
- You have successfully logged in! Redirecting...
- </td>
- </tr>
- </table>
- </div>";
- }
- else{
- echo "<div class=\"formerror\">
- <table border=\"0\">
- <tr>
- <td>
- <img src=\"http://cdn1.iconfinder.com/data/icons/icojoy/noshadow/standart/gif/24x24/001_30.gif\" />
- </td>
- <td>
- Incorrect Username or Password.
- </td>
- </tr>
- </table>
- </div>";
- }
- }
- ?>
- <h2>Login</h2>
- <p>Login now to start seeing Community Service updates!</p>
- <form method="post" action="">
- <table border="0">
- <tr>
- <td align="right">Username</td>
- <td>
- <?php
- if(isset($_POST['submit']))
- echo "<input class=\"inputGood\" type=\"text\" name=\"username\" value=\"$userData[0]\"/>";
- else
- echo "<input class=\"inputGood\" type=\"text\" name=\"username\"/>";
- ?>
- </td>
- </tr>
- <tr>
- </tr>
- <tr>
- <td align="right">Password</td>
- <td><input class="inputGood" type="password" name="password" /></td>
- </tr>
- <tr>
- <td colspan="1" align="center"><input type="submit" name="submit" value=" Login " /></td>
- </tr>
- </table>
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement