The post PHP validate email appeared first on webtoolkit.info.
]]>/**
*
* PHP validate email
* http://www.webtoolkit.info/
*
**/
function isValidEmail($email){
return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email);
}
The post PHP validate email appeared first on webtoolkit.info.
]]>The post PHP password protect appeared first on webtoolkit.info.
]]>/**
*
* PHP password protect
* http://www.webtoolkit.info/
*
**/
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;
}
}
The post PHP password protect appeared first on webtoolkit.info.
]]>The post PHP random password generator appeared first on webtoolkit.info.
]]><?php
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;
}
?>
The post PHP random password generator appeared first on webtoolkit.info.
]]>