Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. <?php
  2. class DBConnector
  3. {
  4.  
  5. private $databaseConnection;
  6.  
  7. function dbConnect()
  8. {
  9. try
  10. {
  11. $this->databaseConnection = new PDO('mysql:host='.$GLOBALS["CONFIGURATION"]["dbservername"] . ';dbname=' . $GLOBALS["CONFIGURATION"]["dbname"], $GLOBALS["CONFIGURATION"]["dbrootuser"], $GLOBALS["CONFIGURATION"]["dbrootpassword"]);
  12.  
  13. }
  14.  
  15. catch(PDOException $e) {
  16. echo 'ERROR: ' . $e->getMessage();
  17. }
  18. }
  19.  
  20. function checkUserPassword($username,$password)
  21. {
  22. try
  23. {
  24. $this->databaseConnection = new PDO('mysql:host='.$GLOBALS["CONFIGURATION"]["dbservername"] . ';dbname=' . $GLOBALS["CONFIGURATION"]["dbname"], $GLOBALS["CONFIGURATION"]["dbrootuser"], $GLOBALS["CONFIGURATION"]["dbrootpassword"]);
  25. }
  26.  
  27. catch(PDOException $e) {
  28. return false;
  29. }
  30.  
  31. //get username record from db
  32. $records = $this->databaseConnection->prepare('SELECT usr_username,usr_password FROM users WHERE usr_username = :username');
  33. $records->bindParam(':username', $username ,PDO::PARAM_STR);
  34. $records->execute();
  35. $results = $records->fetch(PDO::FETCH_NUM);
  36.  
  37. if(!$results)
  38. {
  39. return false;
  40. }
  41. else
  42. {
  43. $saltedPassword = $GLOBALS["CONFIGURATION"]["dbsalt1"] . $password . $GLOBALS["CONFIGURATION"]["dbsalt2"];
  44. $token = hash('ripemd128',"$saltedPassword");
  45.  
  46. if ($results[1]==$token)
  47. return true;
  48. else
  49. return false;
  50. }
  51. }
  52.  
  53. function changePassword($oldPassword)
  54. {
  55. try
  56. {
  57. $this->databaseConnection = new PDO('mysql:host='.$GLOBALS["CONFIGURATION"]["dbservername"] . ';dbname=' . $GLOBALS["CONFIGURATION"]["dbname"], $GLOBALS["CONFIGURATION"]["dbrootuser"], $GLOBALS["CONFIGURATION"]["dbrootpassword"]);
  58. // set the PDO error mode to exception
  59. $this->setAttribute ( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
  60.  
  61. $sql = "UPDATE agis_moulds SET usr_password='Doe' WHERE usr_password = :password";
  62.  
  63. // Prepare statement
  64. $records = $this->prepare($sql);
  65.  
  66. // execute the query
  67. $records->execute();
  68. }
  69.  
  70. catch ( PDOException $e )
  71. {
  72. echo $sql . "<br>" . $e->getMessage ();
  73. }
  74.  
  75. $this->databaseConnection = null;
  76. }
  77. }
  78. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement