我想让我的密码包含小写,大写,8个字符和一个字符

时间:2015-12-13 11:10:32

标签: php login passwords character

我想让我的密码包含小写,大写,8个字符和一个字符。 这是我的代码:

<?php
define('DB_NAME', 'baza');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_HOST', 'localhost');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if (!$db_selected) {
    die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
}
echo 'Your account has been created succesfully! <a href="login.html"> Click here </a> to login.';
$value  = $_POST['name'];
$value2 = $_POST['surename'];
$value3 = $_POST['genre'];
$value4 = $_POST['numrikarteles'];
$value5 = $_POST['email'];
$value6 = $_POST['username'];
$value7 = $_POST['password'];
if (!preg_match('/[^A-Za-z0-9]+/', $value7) || strlen($value7) < 8) {
    echo "Invalid password!";
} //- kushti per ta kontrollu passwordin 
$sql = "INSERT INTO user (name, surename, genre, numrikarteles, email, username,password) VALUES ('$value', '$value2', '$value3', '$value4', '$value5', '$value6', '$value7')";
if (!mysql_query($sql)) {
    die('Error: ' . mysql_error());
}
mysql_close();
?>

1 个答案:

答案 0 :(得分:0)

如果您想限制用户输入包含大写和小写字母以及一个特殊字符的最小8个字符的密码,您可以使用正则表达式,如

^((?=(?:.*[a-zA-Z]){7})(?=(?:.*[@#$%^?])).{8})$