Jump to content

[SOLVED] Password Combination


cashflowtips

Recommended Posts

im looking for solution on how to check the password combination...

 

here is the example: -

 

$text = "onlyalphanumericcharacters012345";

if (ereg('[^A-Za-z0-9]', $text)) {
  echo "This contains characters other than letters and numbers";
}
else {
  echo "This contains only letters and numbers";    
}

 

but the problem here is - i want the code only accept with these kind of combination: -

 

a) alphabet + number

b) alphabet + symbol

c) number + symbol

 

can anyone help me? thanks alot

 

Link to comment
https://forums.phpfreaks.com/topic/68668-solved-password-combination/
Share on other sites

maybe my question is not very clear and i want to apologize for that... let me explain once again...

 

what i really want is the code that can check where the input must have

 

a) must have Alphabet + must have Number (if the input only one of these two, it will return false)

b) must have Alphabet + must have Symbol (the condition same as A(above))

c) must have Number + must have Symbol (the condition same as A(above))

 

as for the Symbol, im not sure what is the basic one that usually been used by other website but i know some of them accept symbol as password characters to increase security (hard for hacker to guess the password)

Are you checking for "at least one alpha" and "at least one number" ?  So these would be valid:

 

Nt4%

NN99

55%%aa

qwer!@#$

 

But these would be invalid

abcd

1234

!@#$

 

because they only contain one class of characters

 

exactly... thanks for more clear view on the question... can u help me with this

Ok, some of that is easy:

 

$got_alpha = preg_match('|[A-Za-z]|', $password);
$got_num = preg_match('|[0-9]|', $password);

 

But as for the symbols.. there are four groups of symbols in the ascii table

 

$got_symbol = preg_match('|[ -/:-@[-`{-~]|', $password);

 

That oughta work.  After that you just need to check

 

if (($got_alpha && $got_num) || ($got_alpha && $got_symbol) || $got_num && $got_symbol))

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.