-5

I want to make my password to contain lowercase, uppercase, 8 characters and a character. Here is my code:

<?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();
?>
o15a3d4l11s2
  • 3,969
  • 3
  • 29
  • 40
Ardi
  • 11
  • 1
  • 6
  • 1
    Possible duplicate of [Password strength check in PHP](http://stackoverflow.com/questions/10752862/password-strength-check-in-php) – jso Dec 13 '15 at 11:13
  • 1
    Welcome to Stack Overflow! Please see [ask] and [The perfect question](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) – Rizier123 Dec 13 '15 at 11:14
  • Please format your question, this is unreadable. – Jan Dec 13 '15 at 11:15
  • 1
    I tried helping you by formatting the code, but it's not possible as it has random words through it. Please take the time to find out how to post questions as people here do want to help. – Trevor Dec 13 '15 at 11:21

1 Answers1

0

If you want to restrict user to enter minimum 8 character password which will contain upper and lower case letter and one special character you can use regular expression like

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