Advertisement
Guest User

tot nu toe

a guest
Jun 27th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. form in profile.php
  2.  
  3. <form id="changepassword" action="/repos/database.php" method="GET" class="well">
  4. <div class="form-group">
  5. <label>Huidige wachtwoord</label>
  6. <input type="password" name="gebruikersnaam" class="form-control" placeholder="Voer wachtwoord in" >
  7. </div>
  8. <div class="form-group">
  9. <label>Nieuw wachtoord:</label>
  10. <input type="password" name="wachtwoord" class="form-control" placeholder="Nieuw wachtwoord" id="txtNewPassword" onchange="checkPasswordSafety();">
  11. <label id="errormeldingveld"> </label>
  12. </div>
  13. <div class="form-group">
  14. <label>Verifieer wachtoord:</label>
  15. <input type="password" name="confirmwachtwoord" class="form-control" placeholder="Verifieer nieuw wachtwoord" id="txtConfirmPassword" onchange="checkpasswordMatch();">
  16. </div>
  17.  
  18. <div>
  19. <label id="divCheckPasswordMatch">
  20. </div>
  21. <button type="submit" class="btn btn-default btn-block" >Verander wachtwoord</button>
  22. </form>
  23.  
  24. database.php
  25. <?php
  26. session_start();
  27.  
  28.  
  29. $db = new database;
  30.  
  31.  
  32.  
  33.  
  34. if($db->verifypassword()){
  35. header ("Location: /admin/index.php");
  36. }else{
  37. header ("Location: /admin/login.php");
  38. #foutmelding geven op de pagina;
  39. }
  40.  
  41.  
  42. class database
  43. {
  44. protected $mysqli ;
  45.  
  46.  
  47. function __construct(){
  48.  
  49. $this->mysqli = new mysqli("localhost","root","","databasenaam");
  50.  
  51. if ($this->mysqli->connect_errno) {
  52. echo "Failed to connect to MySQL: (" . $this->mysqli->connect_errno . ") " . $this->mysqli->connect_error."<br> Contact your database administrator when this error occurs";
  53.  
  54.  
  55.  
  56. }else{
  57.  
  58. }
  59. }
  60.  
  61. function verifypassword(){
  62.  
  63. $user = $_POST['gebruikersnaam'];
  64. $pwd = $_POST['wachtwoord'];
  65.  
  66.  
  67.  
  68. $res = $this->mysqli->query("SELECT wachtwoord FROM inloggegevens WHERE gebruikersnaam = '$user'");
  69.  
  70. $res->data_seek(0);//date seek 0 because there is only 1 result possible
  71. while ($row = $res->fetch_assoc()) {
  72. //echo " wachtwoord = " . $row['wachtwoord'] . "\n";
  73.  
  74. if (password_verify($pwd, $row['wachtwoord']) ) {
  75. $_SESSION['ingelogd'] = $user;
  76.  
  77. //echo "win";
  78.  
  79. if (password_needs_rehash($row['wachtwoord'], PASSWORD_DEFAULT)) {
  80. // Recalculate a new password_hash() and overwrite the one we stored previously
  81.  
  82. $this->updatepassword($pwd);
  83. }
  84. return true;
  85.  
  86. }
  87. else
  88. {
  89.  
  90. return false;
  91.  
  92. }
  93. }
  94.  
  95. }
  96.  
  97. function updatepassword($nieuwwachtwoord){
  98.  
  99. $hashedpwd = password_hash($nieuwwachtwoord,PASSWORD_BCRYPT);
  100. $this->mysqli->query("UPDATE inloggegevens SET wachtwoord = '$hashedpwd' WHERE gebruikersnaam = 'Admin'");
  101. }
  102.  
  103. function createuser($createpassword, $username){
  104. $safepassword = password_hash($createpassword,PASSWORD_BCRYPT);
  105. $this->mysqli->query("INSERT INTO inloggegevens (gebruikersnaam, wachtwoord) VALUES ($username,$safepassword)");
  106. }
  107.  
  108.  
  109. function selectall(){
  110. $res = $this->mysqli->query("SELECT gebruikersnaam FROM inloggegevens ");
  111. return $res;
  112. }
  113. }
  114.  
  115.  
  116. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement