Page 1 of 1
Password Combination
Posted: Mon Sep 10, 2007 2:49 am
by cashflowtips
im looking for solution on how to check the password combination...
here is the example: -
Code: Select all
$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
Posted: Mon Sep 10, 2007 7:32 am
by Hemlata
Hi,
You can get the required results for the combination using following code block...
Code: Select all
// Check the test entered for all the three combinations
$alpha_numeric = ereg('[^A-Za-z0-9]', $text); // alphanumeric check
$alpha_symbol = ereg('[0-9]', $text); // symbol+alphabet check
$num_symbol = ereg('[A-Za-z]', $text); // symbol+number check
// Executes if any match found
if (!$alpha_numeric || !$alpha_symbol || !$num_symbol)
{
echo "<center><font color='#FF0000'>Entered string is valid :: </font>".$text."</center><br>";
}
// else execute
else
{
echo "<center><font color='#FF0000'>Invalid text entered ::</font> ".$text;
}
Hope this helps you..

Re: Password Combination
Posted: Mon Sep 10, 2007 7:52 am
by superdezign
cashflowtips wrote:a) alphabet + number
b) alphabet + symbol
c) number + symbol
As in you don't accept all three?
And what symbols do you accept? You should be specific.
Posted: Mon Sep 10, 2007 9:47 pm
by cashflowtips
Hemlata wrote:Hi,
You can get the required results for the combination using following code block...
Code: Select all
// Check the test entered for all the three combinations
$alpha_numeric = ereg('[^A-Za-z0-9]', $text); // alphanumeric check
$alpha_symbol = ereg('[0-9]', $text); // symbol+alphabet check
$num_symbol = ereg('[A-Za-z]', $text); // symbol+number check
// Executes if any match found
if (!$alpha_numeric || !$alpha_symbol || !$num_symbol)
{
echo "<center><font color='#FF0000'>Entered string is valid :: </font>".$text."</center><br>";
}
// else execute
else
{
echo "<center><font color='#FF0000'>Invalid text entered ::</font> ".$text;
}
Hope this helps you..

first of all, thanks for the code... maybe my question is not very clear... 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)
Posted: Mon Sep 10, 2007 10:12 pm
by Luke
Your question doesn't really make sense to me. Are you saying that the input must have either alphabet + number, OR alphabet + symbol OR number + symbol? Or are you saying that it must meet all of those conditions. Either way, you chose a strange way to ask your question.
Posted: Mon Sep 10, 2007 10:35 pm
by cashflowtips
The Ninja Space Goat wrote:Your question doesn't really make sense to me. Are you saying that the input must have either alphabet + number, OR alphabet + symbol OR number + symbol? Or are you saying that it must meet all of those conditions. Either way, you chose a strange way to ask your question.
ok. lets put it this way,
i put the condition inside if else statement
Code: Select all
if (alphabet+number)
echo "Input granted";
else if (alphabet+symbol)
echo "Input granted";
else if (number+symbol)
echo "Input granted";
else
echo "Input denied";
i want the input must be in combination.
example of input:
input : hello
FALSE
input : hello123
TRUE
input : 12345
FALSE
input : 12345@!#
TRUE
this is what i meant by combination
Posted: Mon Sep 10, 2007 11:28 pm
by superdezign
Again, what is accepted as a symbol? There are a lot of characters in the UNICODE character set.
The smartest way would be to check if there is at least one letter, one number, and one symbol, then add up the boolean results (true = 1, false = 0), then check if that is more than or equal to 2.
Posted: Mon Sep 10, 2007 11:42 pm
by cashflowtips
superdezign wrote:Again, what is accepted as a symbol? There are a lot of characters in the UNICODE character set.
The smartest way would be to check if there is at least one letter, one number, and one symbol, then add up the boolean results (true = 1, false = 0), then check if that is more than or equal to 2.
mmm... lets take something simple like ~`!@#$%^&*()-_+={}[];:<>?/., would this be alright?
Posted: Tue Sep 11, 2007 3:02 am
by Hemlata
Hello
cashflowtips,
The modified script does your requirement of
Code: Select all
if (alphabet+number)
echo "Input granted";
else if (alphabet+symbol)
echo "Input granted";
else if (number+symbol)
echo "Input granted";
else
echo "Input denied";
Script ::
Code: Select all
// Check the text entered for all the combinations
$alphabet = ereg('[^a-zA-Z]', $_POST['txtName']); // alphabet check
$numeric = ereg('[^0-9]', $_POST['txtName']); // numeric check
$symbol = ereg('[a-zA-Z0-9]', $_POST['txtName']); // symbol check
$alpha_numeric = ereg('[^a-zA-Z0-9]', $_POST['txtName']); // alphanumeric check
$alpha_symbol = ereg('[0-9]', $_POST['txtName']); // symbol+alphabet check
$num_symbol = ereg('[A-Za-z]', $_POST['txtName']); // symbol+number check
//executes for alphabet+numeric || symbol+alphabet || symbol+number
if (($alphabet && $numeric && !$alpha_numeric) ||
($alphabet && $symbol && !$alpha_symbol) ||
($symbol && $numeric && !$num_symbol))
{
echo "Entered string is valid";
}
// else execute
else
{
echo "Invalid text entered";
}
Also, script will check '
symbol' as anything except an 'alphabet' or a 'number'
Posted: Tue Sep 11, 2007 3:06 am
by n00b Saibot
you can use regex to apply your logic... use
preg_match() coupled with your set of regex and you have your asnwer.
hint: first one could be [a-zA-Z]+[0-9]+
Posted: Tue Sep 11, 2007 9:48 am
by superdezign
cashflowtips wrote:mmm... lets take something simple like ~`!@#$%^&*()-_+={}[];:<>?/., would this be alright?
Okay then, from there, why can't you figure it out...?
Code: Select all
if ((preg_match('&[A-Za-z]&', $data) + preg_match('&[0-9]&', $data) + preg_match('&[~`!@#$%^\&*()-_+={}\[\];:<>?/.,]&', $data) >= 2) {
// Valid
}
Posted: Tue Sep 11, 2007 9:56 am
by CoderGoblin
When using UTF-8 and preg for one project I seem to remember I had to set the
mb_internal_coding to UTF-8. Probably not relevant here but as UTF-8 has been mentioned thought I would point it out.