Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- form in profile.php
- <form id="changepassword" action="/repos/database.php" method="GET" class="well">
- <div class="form-group">
- <label>Huidige wachtwoord</label>
- <input type="password" name="gebruikersnaam" class="form-control" placeholder="Voer wachtwoord in" >
- </div>
- <div class="form-group">
- <label>Nieuw wachtoord:</label>
- <input type="password" name="wachtwoord" class="form-control" placeholder="Nieuw wachtwoord" id="txtNewPassword" onchange="checkPasswordSafety();">
- <label id="errormeldingveld"> </label>
- </div>
- <div class="form-group">
- <label>Verifieer wachtoord:</label>
- <input type="password" name="confirmwachtwoord" class="form-control" placeholder="Verifieer nieuw wachtwoord" id="txtConfirmPassword" onchange="checkpasswordMatch();">
- </div>
- <div>
- <label id="divCheckPasswordMatch">
- </div>
- <button type="submit" class="btn btn-default btn-block" >Verander wachtwoord</button>
- </form>
- database.php
- <?php
- session_start();
- $db = new database;
- if($db->verifypassword()){
- header ("Location: /admin/index.php");
- }else{
- header ("Location: /admin/login.php");
- #foutmelding geven op de pagina;
- }
- class database
- {
- protected $mysqli ;
- function __construct(){
- $this->mysqli = new mysqli("localhost","root","","databasenaam");
- if ($this->mysqli->connect_errno) {
- echo "Failed to connect to MySQL: (" . $this->mysqli->connect_errno . ") " . $this->mysqli->connect_error."<br> Contact your database administrator when this error occurs";
- }else{
- }
- }
- function verifypassword(){
- $user = $_POST['gebruikersnaam'];
- $pwd = $_POST['wachtwoord'];
- $res = $this->mysqli->query("SELECT wachtwoord FROM inloggegevens WHERE gebruikersnaam = '$user'");
- $res->data_seek(0);//date seek 0 because there is only 1 result possible
- while ($row = $res->fetch_assoc()) {
- //echo " wachtwoord = " . $row['wachtwoord'] . "\n";
- if (password_verify($pwd, $row['wachtwoord']) ) {
- $_SESSION['ingelogd'] = $user;
- //echo "win";
- if (password_needs_rehash($row['wachtwoord'], PASSWORD_DEFAULT)) {
- // Recalculate a new password_hash() and overwrite the one we stored previously
- $this->updatepassword($pwd);
- }
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- function updatepassword($nieuwwachtwoord){
- $hashedpwd = password_hash($nieuwwachtwoord,PASSWORD_BCRYPT);
- $this->mysqli->query("UPDATE inloggegevens SET wachtwoord = '$hashedpwd' WHERE gebruikersnaam = 'Admin'");
- }
- function createuser($createpassword, $username){
- $safepassword = password_hash($createpassword,PASSWORD_BCRYPT);
- $this->mysqli->query("INSERT INTO inloggegevens (gebruikersnaam, wachtwoord) VALUES ($username,$safepassword)");
- }
- function selectall(){
- $res = $this->mysqli->query("SELECT gebruikersnaam FROM inloggegevens ");
- return $res;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement