khalilov 0 Report post Posted August 1, 2008 Whats the php function that generates a random activation code then sends it to the email the user used to sign up. Also how do you check if the inputed email has corrected format? meaning its xxx@something.com Share this post Link to post Share on other sites
toby 0 Report post Posted August 1, 2008 You could do something like a salted hash for the checking address, and regex (preg match) for checking email, though this is probably better done in javascript. Share this post Link to post Share on other sites
yordan 10 Report post Posted August 2, 2008 Also how do you check if the inputed email has corrected format? meaning its xxx@something.comthere are functions in the mail syntax for testing if the address is valid. Returns "true" if the address is valid, and "false" if the address is not valid.Unfortunately I don't know these functions for php, you will have to read the php documentation for that. But this feature is inside all the mailer servers and the mailer clients, so you simply have to find it for php. Share this post Link to post Share on other sites
pyost 0 Report post Posted August 3, 2008 You could do something like a salted hash for the checking address, and regex (preg match) for checking email, though this is probably better done in javascript.If you eventually decide on using JavaScript to validate user input, never forget that it can easily be bypassed! JavaScript can make your web site more user-friendly, but server-side verification, through PHP, is absolutely necessary. There are numerous functions that validate e-mail addresses, and you will have to find the one that you find the best. I've bumped into this one: http://www.phpit.net/rg-erdr.php?_rpo=t. If you use PHP5 (or so it seems), you can use an in-built PHP filter: http://www.w3schools.com/php/filter_validate_email.asp As for the validation string, it can really be anything... You can combine time() with a randomly generated number, and then md5() it Share this post Link to post Share on other sites
TavoxPeru 0 Report post Posted August 10, 2008 (edited) Whats the php function that generates a random activation code then sends it to the email the user used to sign up. Also how do you check if the inputed email has corrected format? meaning its xxx@something.comYou have a lot of choices for the first one, the following code is a very simple function that i use: <?php /*** Generate an activation code* @param int $length is the length of the activation code to generate* @return string*/function generateCode($length = 10){ $password=""; $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; srand((double)microtime()*1000000); for ($i=0; $i<$length; $i++) { $password .= substr ($chars, rand() % strlen($chars), 1); } return $password; } ?> For the second one, you can use the is_valid_email() function to verify the format of any email, also, i strongly recommend you to review the following topic Preventing Spam When Using Php's Mail Function because there you can find a complete review of this and the original article where i got the code. <?php function is_valid_email($email) { return preg_match('#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s]+\.+[a-z]{2,6}))$#si', $email);}?>Other topics that i think can be helpul: Safety Need Help With A PHP - MySQL Registration Script PHP Tutorial: Form Verification And Simple ValidationBest regards, Edited August 10, 2008 by TavoxPeru (see edit history) Share this post Link to post Share on other sites
khalilov 0 Report post Posted August 13, 2008 k i got the email verification (got both java and php) and the random code generator, but i still don't know how to auto-email it :/ Share this post Link to post Share on other sites
Mordent 0 Report post Posted August 13, 2008 Linky Tadaa! I'll leave it to someone else to expand on that, as I haven't the time. Hope that helps, however. Share this post Link to post Share on other sites
TavoxPeru 0 Report post Posted August 20, 2008 While searching my pc for some code that i need i found this two php functions that you can use, the first one for generating your activation code and the second for validate email addresses. generatePassword(): With this function you can set the length and strength of the generated password. <?phpfunction generatePassword($length=9, $strength=0) { $vowels = 'aeuy'; $consonants = 'bdghjmnpqrstvz'; if ($strength & 1) { $consonants .= 'BDGHJLMNPQRSTVWXZ'; } if ($strength & 2) { $vowels .= "AEUY"; } if ($strength & 4) { $consonants .= '23456789'; } if ($strength & 8) { $consonants .= '@#$%'; } $password = ''; $alt = time() % 2; for ($i = 0; $i < $length; $i++) { if ($alt == 1) { $password .= $consonants[(rand() % strlen($consonants))]; $alt = 0; } else { $password .= $vowels[(rand() % strlen($vowels))]; $alt = 1; } } return $password;}?> isValidEmail(): Simple case-insensitive regular expression for email validation that returns TRUE if valid and FALSE if not. <?phpfunction isValidEmail($email){ return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email);}?>Best regards, Share this post Link to post Share on other sites