PHP Classes

File: examples/basic/change.php

Recommend this page to a friend!
  Classes of Subin Siby   Secure PHP Login System   examples/basic/change.php   Download  
File: examples/basic/change.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: Secure PHP Login System
Register and login users using a database via PDO
Author: By
Last change: Update of examples/basic/change.php
Date: 2 months ago
Size: 2,157 bytes
 

Contents

Class file image Download
<?php
require 'config.php';
?>
<!DOCTYPE html>
<html>
    <head>
        <title>Change Password</title>
    </head>
    <body>
        <?php
       
if (isset($_POST['change_password'])) {
            if (isset(
$_POST['current_password']) && $_POST['current_password'] != '' && isset($_POST['new_password']) && $_POST['new_password'] != '' && isset($_POST['retype_password']) && $_POST['retype_password'] != '' && isset($_POST['current_password']) && $_POST['current_password'] != '') {
               
$curpass = $_POST['current_password'];
               
$new_password = $_POST['new_password'];
               
$retype_password = $_POST['retype_password'];

                if (
$new_password != $retype_password) {
                    echo
"<p><h2>Passwords Doesn't match</h2><p>The passwords you entered didn't match. Try again.</p></p>";
                } elseif (
$LS->login($LS->getUser('username'), $curpass, false, false) == false) {
                    echo
'<h2>Current Password Wrong!</h2><p>The password you entered for your account is wrong.</p>';
                } else {
                   
$change_password = $LS->changePassword($new_password);
                    if (
$change_password === true) {
                        echo
'<h2>Password Changed Successfully</h2>';
                    }
                }
            } else {
                echo
'<p><h2>Password Fields was blank</h2><p>Form fields were left blank</p></p>';
            }
        }
       
?>
<form action="<?php echo $LS->curPageURL(); ?>" method='POST'>
            <label>
                <p>Current Password</p>
                <input type='password' name='current_password' />
            </label>
            <label>
                <p>New Password</p>
                <input type='password' name='new_password' />
            </label>
            <label>
                <p>Retype New Password</p>
                <input type='password' name='retype_password' />
            </label>
            <button style="display: block;margin-top: 10px;" name='change_password' type='submit'>Change Password</button>
        </form>
    </body>
</html>