PHP验证电子邮件-密码保护和随机密码
作者:互联网
验证邮箱:
function isValidEmail($email){ return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email); }
随机密码:
function 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; }
密码保护:
function passwordProtect($username, $password){ if ( ( !isset($_SERVER['PHP_AUTH_USER']) || ( isset($_SERVER['PHP_AUTH_USER']) && $_SERVER['PHP_AUTH_USER'] != $username ) ) && ( !isset($_SERVER['PHP_AUTH_PW']) || ( isset($_SERVER['PHP_AUTH_PW']) && $_SERVER['PHP_AUTH_PW'] != $password ) ) ) { header('WWW-Authenticate: Basic realm="Login"'); header('HTTP/1.0 401 Unauthorized'); echo 'Please login to continue.'; exit; } }
标签:consonants,电子邮件,密码保护,AUTH,SERVER,PHP,password,strength 来源: https://www.cnblogs.com/M0rta1s/p/11707839.html