Jump to content

New password to email ?


coop

Recommended Posts

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 password
function 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]


Link to comment
https://forums.phpfreaks.com/topic/32373-new-password-to-email/
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/32373-new-password-to-email/#findComment-150338
Share on other sites

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] 
Link to comment
https://forums.phpfreaks.com/topic/32373-new-password-to-email/#findComment-150738
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.