mysql - How to make a change password PHP script work -
i simpleton less cursory knowledge of programming. have family web site share photos, videos, files , other resources. site has simple login feature begins session, , want able provide people ability alter password 1 time logged in.
the database in mysql , extremely simple only; id, username, and, password columns (not encrypted or hashed @ all).
when comes php , mysql tend research other people's examples , create them own, , login script found easy do. however, have tried , tried , tried find php snippet fits site , allow users alter passwords , have unfortunately failed @ every attempt.
i hoping can assist me in developing have create work site, help hugely appreciated!
my form asks logged in user come in new password, , confirm same password:
<form name="frmchange" role="form" class="form-signin" method="post" action="changepword_script.php"> <div class="form-group"> <label for="inputpassword2">new password</label> <input type="password" class="form-control" id="inputpassword2" placeholder="new password" name="newpassword"> <label for="inputpassword3">confirm new password</label> <input type="password" class="form-control" id="inputpassword3" placeholder="confirm password" name="confirmpassword"> </div> <button class="btn btn-lrg btn-default btn-block" type="submit" value="send">change it</button> </div> </form> and php script (also simple) needs check passwords match , update database if (i have removed ip address of database , replaced zeros):
<?php session_start(); if (!(isset($_session['username']) && $_session['username'] != '')) { header("location:login.php"); } $dbcon = mysql_connect ('000.000.000.00', 'my_db_username', 'my_db_password') $password1 = $_post['newpassword']; $password2 = $_post['confirmpassword']; $password1 = mysql_real_escape_string($password1); $password2 = mysql_real_escape_string($password2); if ($password1 <> $password2) { echo "your passwords not match.";} if (mysql_query(update ebsmembers set password='$password1' username='$session[username]')) {echo "you have changed password.";} mysql_close($dbcon); header("location:login.php"); ?> again, help massively appreciated have struggled making work!
many thanks, paul
tweaked few things errors or didn't create sense me. switched mysqli_*.
<?php session_start(); if (!(isset($_session['username']) || $_session['username'] == '')) { header("location:login.php"); } $dbcon = mysqli_connect('000.000.000.00', 'my_db_username', 'my_db_password', 'my_db_name') or die(mysqli_error($dbcon)); $password1 = mysqli_real_escape_string($dbcon, $_post['newpassword']); $password2 = mysqli_real_escape_string($dbcon, $_post['confirmpassword']); $username = mysqli_real_escape_string($dbcon, $_session['username']); if ($password1 <> $password2) { echo "your passwords not match.";} else if (mysqli_query($dbcon, "update ebsmembers set password='$password1' username='$username'")) {echo "you have changed password.";} else { mysqli_error($dbcon); } mysqli_close($dbcon); ?> php mysql change-password
No comments:
Post a Comment