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
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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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))

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.