Solved

Character limit

Posted on 2003-11-16
7
343 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now