coop Posted December 31, 2006 Share Posted December 31, 2006 Hi all,I'm working on a User authentication system using php and mysql with a flash front end. Everything works fine apart from generating the new password and sending it to email of the person requesting the new password.This is part of the php that generates the new password and updates MySQL.[code=php:0]//New passwordfunction new_password($email){ GLOBAL $db,$table; $email = trim($email); $query1 = mysql_query("SELECT userName from $table WHERE userMail = '$email'"); if(mysql_num_rows($query1)<1){ return "error=email not present into database"; } $row = mysql_fetch_array($query1); $username=$row["userName"]; $query = mysql_query("SELECT * FROM $table WHERE userName = '$username' AND userMail = '$email'"); $rand_string = ''; // --- // generating a random 8 chars lenght password // --- for($a=0;$a<7;$a++){ do{ $newrand = chr(rand(0,256)); } while(!eregi("^[a-z0-9]$",$newrand)); $rand_string .= $newrand; } $pwd_to_insert = md5($rand_string); $new_query = mysql_query("UPDATE $table SET userPassword = '$pwd_to_insert' WHERE userName = '$username' AND userMail = '$email'"); if(!$new_query){ return "error=unable to update value"; }else{ //return "userName=$username&new_pass=$rand_string"; // this send it back to the flash app. // but I wanted to send it by email ? $to = $email; $subject = "Password"; $body = $rand_string; if (mail($to, $subject, $body)) { echo("Message successfully sent!"); } else { echo("Message delivery failed..."); } }}[/code] Quote Link to comment Share on other sites More sharing options...
Orio Posted December 31, 2006 Share Posted December 31, 2006 It doesnt work because you haven't set up the password generation part correctly. Do something like this:[code]<?php$salt = "abcdefghijklmnop123456&^%$#";$rand_string = substr(md5(rand(0,100).time().sha1(str_shuffle($salt))),0,8);?>[/code]This will create a 8 chars long, alpha-numeric and very random password.Orio. Quote Link to comment Share on other sites More sharing options...
coop Posted January 1, 2007 Author Share Posted January 1, 2007 Orio,the password generating works, it's just this part of the code where I'm trying to send it by email.[code=php:0] //return "userName=$username&new_pass=$rand_string"; // this send it back to the flash app. // but I wanted to send it by email ? $to = $email; $subject = "Password"; $body = $rand_string; if (mail($to, $subject, $body)) { echo("Message successfully sent!"); } else { echo("Message delivery failed..."); } }}[/code]this bit sends it back to the LoadVars object in flash that called the function. When I do it this way the password is generated and shown in the falsh app., so I sure that the password generation works, but I want to send t by email instead of showing it in flash.[code=php:0]return "userName=$username&new_pass=$rand_string";[/code] Quote Link to comment Share on other sites More sharing options...
trq Posted January 1, 2007 Share Posted January 1, 2007 Your probably going to at least need to set some [i]From[/i] headers. eg;[code=php:0]$to = $email;$subject = "Password";$body = $rand_string;headers= "From: youremail@yoursite.com\r\n"; if (mail($to, $subject, $body, $headers)) {[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.