php - Update from URL -
i have been working towards updating password after request has been sent , collected email, request part seems work when try update password nothing seems happen, password length set @ 255, checked if correct id getting , seems be, when manually run query in easyphp adding want updated seems work, have looked @ network response no errors showing , checked error logs nothing there either. advice great.
<?php require_once'connection.php'; $userinput = new userinput(); $userinput->triminput(); $id = ''; if( isset( $_get['reset'])) { $id = $_get['reset']; } header('content-type: application/json'); $errors = []; if (empty($_session['resetpassword'])) { $_session['resetpassword'] = 1; } else { $_session['resetpassword']++; } if($_session['resetpassword'] > 3){ $errors[]= ["name"=>"username","error"=>"too many attempts try again in 15 minutes"]; if(!isset($_session["timeoutpassword"])){ $_session['timeoutpassword'] = time(); }; $st = $_session['timeoutpassword'] + 900; if(time() > $st){ unset($_session['resetpassword']); unset($_session['timeoutpassword']); } } else { if(filter_var($_get['password'], filter_validate_regexp,["options"=> [ "regexp" => "/.{6,25}/"]]) === false){ $errors[]= ["name"=>"password","error"=>"invalid password (6 25 characters)"]; } if(!preg_match("/(?=[a-z]*[0-9])(?=[0-9]*[a-z])([a-z0-9-]+)/i",$_get['password'])) { $errors[]= ["name"=>"password","error"=>"password must contain numbers , letters"]; } if($_get['password'] !== $_get['repeatpassword']){ $errors[]= ["name"=>"repeatpassword","error"=>"passwords don't match"]; } if (count($errors) === 0) { try{ $sql = "update username set activecode = 'active', password = :password activecode = :reset"; $stmt = $db->prepare($sql); $stmt->bindvalue(':password', password_hash($_get['password'], password_default)); $stmt->bindvalue(':reset', $id); $stmt->execute(); $stmt->rowcount(); if ( $stmt->rowcount() === 1){ echo json_encode(["success"=>"your password has been reset"]); exit(0); } } catch(exception $e ) { $errors[]= ["name"=>"username","error"=>"unable update password"]; } } } echo json_encode(["errors"=>$errors]);
Comments
Post a Comment