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