Advertisement
Spectrewiz

PHP Problem

Dec 24th, 2012
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.10 KB | None | 0 0
  1. <?php
  2. function checkAccount($username, $password){
  3.     include("INC/dbconnect.inc");/*"INC/dbconnect.inc" is <?php $pdo = new PDO("mysql:host=localhost;dbname=socialnetwork","user","123"); ?>*/
  4.     $select = $pdo->prepare("SELECT id,password FROM users WHERE user_username = :username");
  5.     $select->execute(array(':username'=>$username));
  6.     $q_rows = $select->fetchAll();
  7.     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){
  8.         if($q_rows[0][1]/*the password of the user*/ == $password)
  9.             return "true";
  10.         else
  11.             return "false";
  12.     }
  13.     else
  14.         return "false";
  15.     $pdo=null;
  16. }
  17.  
  18. if(isset($_POST["submit"])){
  19.     $userData = array();
  20.     $userData[0] = $_POST['username'];
  21.     $userData[1] = hash("sha512", $_POST['password']);
  22.    
  23.     if(checkAccount($userData[0], $userData[1])){
  24.         echo "<div class=\"formconfirm\">
  25.             <table border=\"0\">
  26.             <tr>
  27.             <td>
  28.             <img src=\"http://cdn1.iconfinder.com/data/icons/onebit/PNG/onebit_34.png\" />
  29.             </td>
  30.             <td>
  31.             You have successfully logged in! Redirecting...
  32.             </td>
  33.             </tr>
  34.             </table>
  35.             </div>";
  36.     }
  37.     else{
  38.         echo "<div class=\"formerror\">
  39.             <table border=\"0\">
  40.             <tr>
  41.             <td>
  42.             <img src=\"http://cdn1.iconfinder.com/data/icons/icojoy/noshadow/standart/gif/24x24/001_30.gif\" />
  43.             </td>
  44.             <td>
  45.             Incorrect Username or Password.
  46.             </td>
  47.             </tr>
  48.             </table>
  49.             </div>";
  50.     }
  51. }
  52.  
  53. ?>
  54. <h2>Login</h2>
  55. <p>Login now to start seeing Community Service updates!</p>
  56. <form method="post" action="">
  57. <table border="0">
  58.     <tr>
  59.     <td align="right">Username</td>
  60.     <td>
  61.     <?php
  62.     if(isset($_POST['submit']))
  63.         echo "<input class=\"inputGood\" type=\"text\" name=\"username\" value=\"$userData[0]\"/>";
  64.     else
  65.         echo "<input class=\"inputGood\" type=\"text\" name=\"username\"/>";
  66.     ?>
  67.     </td>
  68.     </tr>
  69. <tr>
  70. </tr>
  71.     <tr>
  72.     <td align="right">Password</td>
  73.     <td><input class="inputGood" type="password" name="password" /></td>
  74. </tr>
  75. <tr>
  76. <td colspan="1" align="center"><input type="submit" name="submit" value="    Login    " /></td>
  77. </tr>
  78. </table>
  79. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement