| 1 | <?php |
| 2 | function request_password() { |
| 3 | global $db,$error; |
| 4 | $login=addslashes($_POST['login']); |
| 5 | $login_type=$_POST['login_type']; |
| 6 | $email=$_POST['email']; |
| 7 | |
| 8 | if ($login == '') { |
| 9 | $error="Please enter name or id"; |
| 10 | return false; |
| 11 | } |
| 12 | |
| 13 | if ((strpos($email, '@') == false) || (strpos($email, '@') == '0') || (strpos($email, '@') >= (strlen($email) - 4))) { |
| 14 | $error="Please enter correct mail"; |
| 15 | return false; |
| 16 | } |
| 17 | |
| 18 | switch ($login_type) { |
| 19 | case "name": |
| 20 | $set=$db->query("select * from users where login='$login' and email='$email'"); |
| 21 | $set->next(); |
| 22 | $user_name=$set->getString('login'); |
| 23 | $user_id=$set->getString('user_id'); |
| 24 | break; |
| 25 | case "id": |
| 26 | $set=$db->query("select * from users where user_id='$login' and email='$email'"); |
| 27 | $set->next(); |
| 28 | $user_name=$set->getString('login'); |
| 29 | $user_id=$set->getString('user_id'); |
| 30 | break; |
| 31 | } |
| 32 | |
| 33 | if($set->getNumRows() == 0) { |
| 34 | $error="Name [or id] that you entered do not match your mail"; |
| 35 | return false; |
| 36 | } |
| 37 | |
| 38 | $vercode=md5(uniqid(rand())); |
| 39 | $vercode=substr($vercode,0,23); |
| 40 | |
| 41 | $q="update users set hash='$vercode' where user_id='$user_id'"; |
| 42 | $db->query($q); |
| 43 | |
| 44 | $emailtext= "Ahoj $user_name!\nPotrebujes zmenit heslo ktore si zabudol?\nPrave od toho tu je tento email. Musim tento text trosku natiahnut aby ho spamfiltre nebrali ako spam a ty si si to svoje zabudnute heslo mohol lahko zmenit.\nTu je tvoje overovacie cislo => $vercode <= [samozrejme bez tych sipiek => a <=].\nTen musis zadat na tejto adrese => https://".SYSTEM_URL."/id/632663 kde si uz svoje heslo lahko zmenis.\n\nVela Stastia\nadmini ".SYSTEM_URL; |
| 45 | $headers = 'From: root@kyberia.cz' . "\r\n" . 'X-Mailer: kyberia'; |
| 46 | mail($email,SYSTEM_URL." verification code",$emailtext,$headers ); |
| 47 | |
| 48 | $error="<h3>Verification code sent, please check your mailbox.</h3>"; |
| 49 | return false; |
| 50 | } |
| 51 | ?> |