Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Check authed
- require_once "auth.php";
- //Start session
- session_start();
- //Include database connection details
- require_once('config.php');
- //Array to store validation errors
- $errmsg_arr = array();
- //Validation error flag
- $errflag = false;
- //Connect to mysql server
- $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
- if(!$link) {
- die('Failed to connect to server: ' . mysql_error());
- }
- //Select database
- $db = mysql_select_db(DB_DATABASE);
- if(!$db) {
- die("Unable to select database");
- }
- //Function to sanitize values received from the form. Prevents SQL injection
- function clean($str) {
- $str = @trim($str);
- if(get_magic_quotes_gpc()) {
- $str = stripslashes($str);
- }
- return mysql_real_escape_string($str);
- }
- //Sanitize the POST values
- $newpass = clean($_POST['newpass']);
- $repeat = clean($_POST['repeat']);
- $oldpass = clean($_POST['oldpass']);
- $user = clean($_POST['user']);
- //Input Validations
- if($user == '') {
- $errmsg_arr[] = 'User ID missing';
- $errflag = true;
- }
- if($newpass == '') {
- $errmsg_arr[] = 'Newpass ID missing';
- $errflag = true;
- }
- if($repeat == '') {
- $errmsg_arr[] = 'Repeat pass ID missing';
- $errflag = true;
- }
- if($oldpass == '') {
- $errmsg_arr[] = 'Old Password missing';
- $errflag = true;
- }
- if($newpass != $repeat) {
- $errmsg_arr[] = 'Passwords dont match!';
- $errflag = true;
- }
- //If there are input validations, redirect back to the login form
- if($errflag) {
- $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
- session_write_close();
- exit();
- }
- //Create query
- $qry="SELECT * FROM members WHERE login='$user' AND passwd='".md5($_POST['oldpass'])."'";
- $result=mysql_query($qry);
- //Check whether the query was successful or not
- if($result) {
- if(mysql_num_rows($result) == 1) {
- //Login Successful
- $qry2 = "UPDATE members SET `passwd` = '".md5($_POST['newpass'])."' WHERE `login` = '$user'";
- $result2 = @mysql_query($qry2);
- }}
- //Check whether the query was successful or not
- if($result2) {
- header("location: pwchange-success.php");
- exit();
- }
- else {
- die("Its not working!");
- header("location: pwchange-form.php");
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement