Is this User ID & password check safe enough?

Please take a look at my code below and tell me if I’m doing the right thing here. My wishes:

Username

  • The username must be at least 6 characters wrong
  • The username can’t contain any special symbols

Password:

  • The password must be at least 8 characters
  • The password must contain at least 1 upper- and lowercase letter
  • The password can’t contain any special symbols

As you can see I am also using an encrypt function for the password. Does this effect my code at all?
PHPCodeChecker.com doesn’t give me any errors, but I think I’m missing something obvious here.

//password encrypt function
function encrypt($password) {
    return base64_encode(pack("H*", sha1(utf8_encode($password))));
}

$str =  encrypt($_POST['password']);
$pass = mysqli_real_escape_string($db_link, $str);
$repass = mysqli_real_escape_string($db_link, $_POST['repeat_password']);
$user = mysqli_real_escape_string($db_link, $_POST['name']);

$uppercase = preg_match('@[A-Z]@', $pass);
$lowercase = preg_match('@[a-z]@', $pass);
$number    = preg_match('@[0-9]@', $pass);

if(!$uppercase || !$lowercase || !$number || !ctype_alnum($password) || strlen($password) < 8) {

    echo "The password must contain at least 1 lowercase letter, 1 uppercase letter and 1 number.";
    echo "The password can't contain special symbols.";

} else if ($pass != $repass) {
    echo "Passwords do not match";
} else if ($user == '' && strlen($user) < 6 && !ctype_alnum($user)) {
    echo "The User ID must be at least 6 characters long and can't contain special symbols.";
} else {
    $db_add = mysqli_query( "INSERT INTO `accounts` VALUES ('$user', '$pass', '0', '0', '')" ) or die( 'Error: '.mysqli_error() );  
    echo 'Account created';
}