hii everyone,
i developed a small database driven website, in that when a new user gets registered, an email will be sent to tht user with his/her login information details,
i'm now displaying the username and password(password as a clear text) in the mail.
my client asked me not to display the password as a clear text instead they should be replaced by astricks.
its not a problem at all, i'm using smarty templates text files for email.
can anyone help me out.
example is: if user registered password is "PHPMYSQL" i need to display this as "P******L"
thanks,
php mail function..
Moderator: General Moderators
- pavanpuligandla
- Forum Contributor
- Posts: 130
- Joined: Thu Feb 07, 2008 8:25 am
- Location: Hyderabad, India
Re: php mail function..
Hi there.
I'm not sure if this is an ideal way of doing it, but it's a working solution.
Here's the code:
Here's the breakdown for it:
$newpassword is made up of 3 parts:
1. The starting character of the password, so $password{0} refers to the first character in the string
2. A couple of functions are used together here: first, substr is used to chop off the starting and ending characters of the string. Second, strlen is used to count the total characters in the string. And finally, str_repeat is used to repeat an asterisk that many times--so this will work with any length password.
3. And the ending character is appended using $password{strlen($password)-1}
A couple of notes: A password that is 2 characters long, for example the password "HI" will always be "HI", Other than that, you also might consider simply using a fixed amount of asterisks, which would be as simple as replacing number 2 with "******"
Good luck, I hope this helps.
I'm not sure if this is an ideal way of doing it, but it's a working solution.
Here's the code:
Code: Select all
$password = "PHPMYSQL";
$newpassword = $password{0}.str_repeat("*", strlen(substr($password, 1, -1))).$password{strlen($password)-1};
echo $newpassword;$newpassword is made up of 3 parts:
1. The starting character of the password, so $password{0} refers to the first character in the string
2. A couple of functions are used together here: first, substr is used to chop off the starting and ending characters of the string. Second, strlen is used to count the total characters in the string. And finally, str_repeat is used to repeat an asterisk that many times--so this will work with any length password.
3. And the ending character is appended using $password{strlen($password)-1}
A couple of notes: A password that is 2 characters long, for example the password "HI" will always be "HI", Other than that, you also might consider simply using a fixed amount of asterisks, which would be as simple as replacing number 2 with "******"
Good luck, I hope this helps.
- pavanpuligandla
- Forum Contributor
- Posts: 130
- Joined: Thu Feb 07, 2008 8:25 am
- Location: Hyderabad, India
Re: php mail function..
hii,
thanks for your help,
but it didnot work.
here's my registration functions code.
nothing happened when i changed this code. please let me know the solution.
many thanks again for making your time.
thanks for your help,
but it didnot work.
here's my registration functions code.
Code: Select all
// *****************************************************************************
// Purpose send notification message to email
// Inputs
// $login - login
// $cust_password - password
// $newpassword - newpassword (Password sent to user's email with *'s)
// $Email - email
// $first_name - customer first name
// $last_name - customer last name
// $subscribed4news - if 1 customer is subscribed to news
// $additional_field_values - additional field values is array of item
// "additional_field" is value of this field
// key is reg_field_ID
// $updateOperation - 1 if customer info is updated, 0
// otherwise
// Remarks
// Returns
$cust_password = cryptPasswordCrypt( $cust_password, null );
$newpassword = $cust_password{0}.str_repeat("*", strlen(substr($cust_password, 1, -1))).$cust_password{strlen($cust_password)-1};
function regEmailNotification($smarty_mail, $login, $newpassword, $Email, $first_name,
$last_name, $subscribed4news, $additional_field_values,
$countryID, $zoneID, $state, $zip, $city, $address, $updateOperation )
{
$user = array();
$smarty_mail->assign( "login", $login );
$smarty_mail->assign( "newpassword", $newpassword );
$smarty_mail->assign( "first_name", $first_name );
$smarty_mail->assign( "last_name", $last_name );
$smarty_mail->assign( "Email", $Email );
$additional_field_values = GetRegFieldsValues( $login );
$smarty_mail->assign( "additional_field_values", $additional_field_values );
$addresses = regGetAllAddressesByLogin( $login );
for( $i=0; $i<count($addresses); $i++ )
$addresses[$i]["addressStr"] = regGetAddressStr( $addresses[$i]["addressID"] , true);
$smarty_mail->assign( "addresses", $addresses );
if(CONF_ENABLE_REGCONFIRMATION){
$sql = '
SELECT ActivationCode FROM '.CUSTOMERS_TABLE.'
WHERE Login="'.xEscapeSQLstring($login).'" AND cust_password="'.xEscapeSQLstring(cryptPasswordCrypt($cust_password, null)).'"
';
@list($ActivationCode) = db_fetch_row(db_query($sql));
$smarty_mail->assign('ActURL', CONF_FULL_SHOP_URL.(substr(CONF_FULL_SHOP_URL, strlen(CONF_FULL_SHOP_URL)-1,1)=='/'?'':'/').'index.php?act_customer=1&act_code='.$ActivationCode);
$smarty_mail->assign('ActCode', $ActivationCode);
}
$html = $smarty_mail->fetch( "register_successful.txt" );
ss_mail($Email,
EMAIL_REGISTRATION,
$html,
"From: \"".CONF_SHOP_NAME."\"<".CONF_GENERAL_EMAIL.">\n".
stripslashes(EMAIL_MESSAGE_PARAMETERS)."\nReturn-path: <".CONF_GENERAL_EMAIL.">");
}
many thanks again for making your time.
- pavanpuligandla
- Forum Contributor
- Posts: 130
- Joined: Thu Feb 07, 2008 8:25 am
- Location: Hyderabad, India
Re: php mail function..
hii,
i'vent declared my varibales properly. its working now..
many thanks for ur help..
By the way in our registration form, password should contain minimum of 8 characters, so no need to worry about 2 charactered string.
thanks again..
i'vent declared my varibales properly. its working now..
many thanks for ur help..
By the way in our registration form, password should contain minimum of 8 characters, so no need to worry about 2 charactered string.
thanks again..
Re: php mail function..
why the long road ?
<input type=password ......................
<input type=password ......................
- pavanpuligandla
- Forum Contributor
- Posts: 130
- Joined: Thu Feb 07, 2008 8:25 am
- Location: Hyderabad, India
Re: php mail function..
hii..why the long road ?
<input type=password ......................
i'm using .txt files as email templates which were compiled by smarty engine..
so should need to go in this long way only..
Re: php mail function..
ah ok, i thought they were html you were trying to produce. since it is text, you would have to manufacture the asteriks i guess.