PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/coopcoffeebeans/Customer/password.php

https://github.com/gypsyfarm/gypsyfarm
PHP | 98 lines | 71 code | 18 blank | 9 comment | 11 complexity | d81a6dc61fc75e91472117c5cf9874fc MD5 | raw file
  1. <?php
  2. session_start();
  3. require("../functions.php");
  4. require("../tables.php");
  5. // check security
  6. // check session variable
  7. if (isset($_SESSION['valid_user']))
  8. {
  9. $contact_id = $_SESSION['contact_id'];
  10. $valid_user = $_SESSION['valid_user'];
  11. }
  12. else
  13. {
  14. header("Location: http://www.coopercoffeesbeans.com/badlogin.php");
  15. }
  16. // provide form to log in
  17. if (!isset($_REQUEST['button']))
  18. {
  19. logo();
  20. echo "<br><center><h1 >Password Update</h1></center><br><br><br><br>";
  21. echo "<font size=4 color=black>You are about to change the login password for $valid_user</font>";
  22. echo '<form method="post" action="password.php">';
  23. echo '<table>';
  24. echo '<tr><td>Enter Current Password:</td>';
  25. echo '<td><input type="password" name="current"></td></tr>';
  26. echo '<tr><td><br></td></tr>';
  27. echo '<tr><td>Enter New Password:</td>';
  28. echo '<td><input type="password" name="New_Password:"></td></tr>';
  29. echo '<tr><td>Confirm New Password:</td>';
  30. echo '<td><input type="password" name="Confirm_Password:"></td></tr>';
  31. echo '<tr><td colspan="2" align="center">';
  32. echo '<input type="submit" name="button" value="Save Password"></td>';
  33. echo '<td colspan="2">';
  34. echo '<input type="submit" name="button" value="Cancel"></td></tr>';
  35. echo '</table></form>';
  36. }
  37. If ($_REQUEST['button'] == 'Save Password'){
  38. logo();
  39. echo "<br><center><h1 >Update Password</h1></center><br><br><br><br>";
  40. echo '<font size=3><a href="../index.php">Back to Main Menu</font><br>';
  41. echo '<font size=3><a href="../logout.php">Log out</a></font><br>';
  42. $New=$_REQUEST['New_Password:'];
  43. $Confirm=$_REQUEST['Confirm_Password:'];
  44. $password = $_REQUEST['current'];
  45. $db_conn = mysql_connect('mysql.coopcoffeesbeans.com', 'greenbeans3', 'annh401');
  46. mysql_select_db('cbeans', $db_conn);
  47. $query ="select a.cust_id as contact_id, cc.company, cc.name, a.user_type
  48. FROM $tbl_auth a, $tbl_coop_contact cc
  49. WHERE a.cust_id='$contact_id'
  50. AND a.cust_id=cc.contact_id
  51. AND a.pass = old_password('$password')";
  52. # echo "<br>$query<br>";
  53. $result = mysql_query($query, $db_conn);
  54. //If they are not showing up in the datset with the password they entered then it must be wrong
  55. if (mysql_num_rows($result) == 0 ){
  56. echo '<font size=3><a href="password.php">Back to Change Password</a></font><br>';
  57. echo '<br><br><font size=4 color=red>You need to enter a valid password before the change can be made</font>';
  58. }
  59. //If its right and the new matches the confirm and at least one of them is set then update the password
  60. else if (($New == $Confirm) and (isset($New))) {
  61. $db_conn = mysql_connect('mysql.coopcoffeesbeans.com', 'greenbeans3', 'annh401');
  62. mysql_select_db('greenbeans', $db_conn);
  63. // $query = "UPDATE `auth` SET `pass` = password( '$New' ) WHERE `name` = '$contact_id' LIMIT 1 ";
  64. $query = "UPDATE $tbl_auth SET pass = old_password('$New') WHERE cust_id = '$contact_id' LIMIT 1 ";
  65. $result = mysql_query($query, $db_conn);
  66. echo '<br><font size=4 color=Red>Your password has been changed. Please make a note of it,</font><br>';
  67. echo '<font size=4 color=Red>you will need it the next time you log in.</font>';
  68. }
  69. //Otherwise the new password and confirmatin must not match
  70. else {
  71. echo '<font size=3><a href="password.php">Back to Change Password</a></font><br>';
  72. echo '<br><br><font size=4 color=red>The new password and the confirmation do not match, you must have a typo!</font>';
  73. }
  74. }
  75. //They just canceled out of the page altogether
  76. If ($_REQUEST['button'] == 'Cancel'){
  77. header("Location: http://www.coopercoffeesbeans.com/index.php");
  78. echo 'You have chosen cancel';
  79. }
  80. ?>