Solved

Character limit

Posted on 2003-11-16
7
373 Views
Last Modified: 2013-12-03
Hi,

I need a script that will check if a variable is 7 characters long or else spit out an error. This is just for the sign up password value on my site, since i dont want peaple getting their account stolen so easy.

Also, I tried this out and was wondering if you could tell me why it doesnt work.

if (!preg_match("/.*.*.*.*.*.*.*/", $_POST['passwd'])) {
            echo('Password needs to be 7 characters long.');
            include('register.html');
            exit();
      }


Thanks.
0
Comment
Question by:TaintedGod
  • 4
  • 2
7 Comments
 
LVL 19

Accepted Solution

by:
Michael701 earned 125 total points
ID: 9758811
if strlen('passwd')<7) {
            echo('Password needs to be 7 characters long.');
            include('register.html');
            exit();
      }

I assume you want 7 or more characters. if you really want every password to be exactly 7 characters then change the < to ==

0
 
LVL 6

Expert Comment

by:mattjp88
ID: 9758866
Well, you could do this with javascript.  In the <input> tag, just put maxlength=7, that will prevent users from entering a longer password.  So this is what your <input> tag would oook like:

<input type="password" maxlength="7" name="password">

-Matt
0
 
LVL 2

Author Comment

by:TaintedGod
ID: 9759361
Michael701

Before i even try this code i can tell there is an error in there, and since ive never used this function before im not sure where the brackets go, please look this over. Thanks.

mattjp88

Thanks for the post but, i did post this question in the PHP section and not in Javascript.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 2

Author Comment

by:TaintedGod
ID: 9759416
Ah nevermind, i fixed it myself......It should of been:

if (strlen($_POST['passwd'] < 7)) {
             echo('Password needs to be 7 characters long.');
             include('register.html');
             exit();
      }

Thanks anyways.
0
 
LVL 2

Author Comment

by:TaintedGod
ID: 9759490
That's odd.....I dont get an error message but I get my echo message everytime.
0
 
LVL 19

Expert Comment

by:Michael701
ID: 9759965
you miss placed a )

if (strlen($_POST['passwd']) < 7) {
             echo('Password needs to be 7 characters long.');
             include('register.html');
             exit();
      }

Thanks anyways
0
 
LVL 2

Author Comment

by:TaintedGod
ID: 9760086
That looks better :P
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question