Jump to content

Password integrity


karldesign

Recommended Posts

Hi all,

 

I am doing a registration for a website and want to check the password meets the following requirements:

 

1) 6 chars at least

2) A-Z/a-z/0-9 only (no characters)

 

I have worked out how to check for (1) - if(strlen($_POST['formPassword']) < 6) - and I just need to work out how to check for just letters and numbers (2).

 

Any help would be great...

Link to comment
https://forums.phpfreaks.com/topic/98969-password-integrity/
Share on other sites

The best way to check if a string is alphanumeric (Has only letters/numbers) imo is using ctype_alnum(). Example:

 

<?php

$str = '12abCD19z4';
if (ctype_alnum($str)) {
echo "Letters or digits only";

?>

 

 

In the tests I've made in the past, this function was faster than using preg_match() ot eregi().

If you still wanna go for the eregi() way:

 

<?php

if(eregi("^[0-9a-z]{6,}$", $_POST['formPassword']))
echo "Letters or digits only, and six chars at least";

?>

 

This would also check if the string has at least 6 chars

 

 

Orio.

Link to comment
https://forums.phpfreaks.com/topic/98969-password-integrity/#findComment-506429
Share on other sites

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.