diff options
| author | oweissbarth | 2014-03-17 00:38:59 +0100 |
|---|---|---|
| committer | oweissbarth | 2014-03-17 00:38:59 +0100 |
| commit | 400b575178557322fe394904dc204be69cdab624 (patch) | |
| tree | f068445b5ee79781f86923dfb36408a8d9c35e46 | |
| parent | ac384ab0feee6fc6761d0030273c665264dd33e1 (diff) | |
| parent | a4118da1cc89d897e96fa0ca27f4e44cca84391d (diff) | |
| download | files.iamfabulous.de-400b575178557322fe394904dc204be69cdab624.tar.gz | |
Merge branch 'master' of git.iamfabulous.de:files.iamfabulous.de
| -rw-r--r-- | www/constants.php | 3 | ||||
| -rw-r--r-- | www/functions/func_password.php | 33 |
2 files changed, 36 insertions, 0 deletions
diff --git a/www/constants.php b/www/constants.php index 0b22908..1717291 100644 --- a/www/constants.php +++ b/www/constants.php @@ -26,3 +26,6 @@ define("PASSWORD_SUCCESS", 18); define("PASSWORD_PASSWORD", 19); define("PASSWORD_DATABASE", 20); +define("PASSWORD_SUCCESS", 21); +define("PASSWORD_EMAIL", 22); +define("PASSWORD_PROHIBITED", 23); diff --git a/www/functions/func_password.php b/www/functions/func_password.php index 9d2d08a..486e9ba 100644 --- a/www/functions/func_password.php +++ b/www/functions/func_password.php @@ -28,3 +28,36 @@ function change_password($db, $first_password, $second_password){ return PASSWORD_DATABASE; } } + +function recover_password($db){ + $test_email_db = $db->query("SELECT 1 FROM user WHERE email='" . SQLite3::escapeString($_POST['email']) . "';"); + $test_email_ar = $test_email_db->fetchArray(SQLITE3_NUM); + + if($test_email_ar[0] == 1){ + $password_array = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "_", "-", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ); + + $length = count($password_array); + $password = ""; + + for ($i=0;$i<21;$i++){ + $index = mt_rand(0,$length-1); + $password = "$password".$password_array[$index]; + } + + $var = change_password($db, $password, $password); + + if($var == PASSWORD_SUCCESS){ + + $subject = "Your new password is" . $password; + if(mail($_POST['email'], "New password", $subject, "From: mail@iamfabulous.de")){ + return RECOVER_SUCCESS; + } else { + return RECOVER_EMAIL; + } + } else { + return $var; + } + } else { + return RECOVER_PROHIBITED; + } +} |
