summaryrefslogtreecommitdiff
path: root/www/functions/func_password.php
diff options
context:
space:
mode:
authorHorus32014-03-17 00:01:19 +0100
committerHorus32014-03-17 00:01:19 +0100
commita4118da1cc89d897e96fa0ca27f4e44cca84391d (patch)
tree9777b1e444f564172ecee417c34ded8886ca3ae2 /www/functions/func_password.php
parentd5bd89e1d64d00f0d10926c470bc850646f4a969 (diff)
downloadfiles.iamfabulous.de-a4118da1cc89d897e96fa0ca27f4e44cca84391d.tar.gz
Added func recover_password
Diffstat (limited to 'www/functions/func_password.php')
-rw-r--r--www/functions/func_password.php33
1 files changed, 33 insertions, 0 deletions
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;
+ }
+}