What's new

PHP Password Strength (PHP)

M H I N Y E

Forum Guru
Elite
Joined
May 11, 2018
Posts
3,641
Solutions
5
Reaction
5,772
Points
1,613
Mga master patulong po kung pano ung tamang statement para strong password lng ung e accept o store sa database

ito po yung code
PHP:
if ($stmt->num_rows > 0) {
            echo 'Username exists, please choose another!';
        } else
        {
            if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
                exit('Email is not valid!');
            }
            if (preg_match('/^[a-zA-Z0-9]+$/', $_POST['username']) == 0) {
                exit('Username is not valid!');
            }
            if (strlen('/^[a-zA-Z0-9]+$/', $_POST['password']) == 0) {
                exit('Password must be strong');
            }

1669549892198.png
 

Attachments

ayaw parin boss tinatanggap parin nya kahit walang uppercase number special character
my fault HAHAHA mali pala regex ko dito...

try mo to:
PHP:
if(preg_match('/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$/' , $_POST['password'])) {

if you want explanation sa regex, reply lang
 
Last edited:
my fault HAHAHA mali pala regex ko dito...

try mo to:
PHP:
if(preg_match('/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$/' , $_POST['password'])) {

if you want explanation sa regex, reply lang
cge boss wait try ko

my fault HAHAHA mali pala regex ko dito...

try mo to:
PHP:
if(preg_match('/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$/' , $_POST['password'])) {

if you want explanation sa regex, reply lang
alaws parin boss tinatanggap parin kahit walang uppercase, number special char. ect...

my fault HAHAHA mali pala regex ko dito...

try mo to:
PHP:
if(preg_match('/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$/' , $_POST['password'])) {

if you want explanation sa regex, reply lang
PHP:
{
            if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
                exit('Email is not valid!');
            }
            if (preg_match('/^[a-zA-Z0-9]+$/', $_POST['username']) == 0) {
                exit('Username is not valid!');
            }
            if(preg_match('/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$/' , $_POST['password'])) {
                exit('Password must be strong');
            }
           
           
            if ($stmt = $con->prepare('INSERT INTO accounts (username, password, email) VALUES (?, ?, ?)'))
            {
                // Hashing, salting and peppering the password.
                $password = $_POST['password'];
                $salt = bin2hex($password);
                $pepper = 'syntax';
                $pswrd = $salt.$pepper.$password;
                $password = password_hash($pswrd, PASSWORD_DEFAULT);
                $stmt->bind_param('sss', $_POST['username'], $password , $_POST['email']);
                $stmt->execute();
                echo 'You have successfully registered, you can now login!';
               
            } else
            {
                echo 'Could not prepare statement!';
            }
        }
 
Last edited:

Similar threads

Back
Top