diff options
| author | Horus3 | 2014-03-17 00:01:19 +0100 |
|---|---|---|
| committer | Horus3 | 2014-03-17 00:01:19 +0100 |
| commit | a4118da1cc89d897e96fa0ca27f4e44cca84391d (patch) | |
| tree | 9777b1e444f564172ecee417c34ded8886ca3ae2 | |
| parent | d5bd89e1d64d00f0d10926c470bc850646f4a969 (diff) | |
| download | files.iamfabulous.de-a4118da1cc89d897e96fa0ca27f4e44cca84391d.tar.gz | |
Added func recover_password
| -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; + } +} |
