diff --git a/passwordchange.php b/passwordchange.php
new file mode 100644
index 0000000..2ff0423
--- /dev/null
+++ b/passwordchange.php
@@ -0,0 +1,79 @@
+
+
+
+
+
+ Change Password
+
+
+');
+}
+
+$userid = $_GET['userid'];
+$code = $_GET['code'];
+
+
+$statement = $pdo->prepare("SELECT * FROM users WHERE id = :userid");
+$result = $statement->execute(array('userid' => $userid));
+$user = $statement->fetch();
+
+//check if theres a code for the user delivered
+if($user === null || $user['passwordcode'] === null) {
+ die('No User matching your request.');
+}
+
+if($user['passwordcode_time'] === null || strtotime($user['passwordcode_time']) < (time()-24*3600) ) {
+ die('Ooops. This code isnt valid anymore.');
+}
+
+
+
+if(sha1($code) != $user['passwordcode']) {
+ die('');
+}
+
+
+
+if(isset($_GET['send'])) {
+ $password = $_POST['password'];
+ $password_confirm = $_POST['password_confirm'];
+ //regexes for passvalidation:
+ $REuppercase = preg_match('@[A-Z]@', $password);
+ $RElowercase = preg_match('@[a-z]@', $password);
+ $REnumber = preg_match('@[0-9]@', $password);
+ $REspecialChars = preg_match('@[^\w]@', $password);
+ if($password != $password_confirm) {
+ echo "password or confirmed password wrong";
+ }
+ if(!$REuppercase || !$RElowercase || !$REnumber || !$REspecialChars || strlen($password) < 8) {
+ echo 'Password needs to be more complex.
';
+ echo 'Please implement at least 8 chars, upper & downer caser, one number & one special char.
';
+ $error = true;
+} else {
+ $passwordhash = password_hash($password, PASSWORD_DEFAULT);
+ $statement = $pdo->prepare("UPDATE users SET password = :passwordhash, passwordcode = NULL, passwordcode_time = NULL WHERE id = :userid");
+ $result = $statement->execute(array('passwordhash' => $passwordhash, 'userid'=> $userid ));
+
+ if($result) {
+ die('Changed password. Going to login now.');
+ }
+ }
+}
+?>
+
+Set new password
+
\ No newline at end of file
diff --git a/secondauth.php b/secondauth.php
index d31e3bf..66c5289 100644
--- a/secondauth.php
+++ b/secondauth.php
@@ -1,7 +1,29 @@
prepare("UPDATE users SET passwordcode = :passwordcode, passwordcode_time = NOW() WHERE id = :userid");
+ $result = $statement->execute(array('passwordcode' => sha1($passwordcode), 'userid' => $user['id']));
+
+
if(isset($_GET['login'])) {
$username = $_POST['username'];
$password = $_POST['password'];
@@ -16,7 +38,7 @@ if(isset($_GET['login'])) {
$_SESSION['username'] = $user['username'];
$_SESSION['givenName'] = $user['givenName'];
$_SESSION['lastName'] = $user['lastName'];
- die('successfull. go to: password change page');
+ die('successfull. please wait. youll be forwarded! ');
} else {
$errorMessage = "somethings wrong (maybe wrong password or invalid session)
";
}