473,387 Members | 1,624 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

validate password..

vikas1111
122 100+
Hi All

I Want to validate password,, the condition is that first 2 letters must be numbers and remaining 4 must be alphabets..How can i solve this ????
Jun 5 '08 #1
7 1858
rizwan6feb
108 100+
This could be 1 of many solutions
Expand|Select|Wrap|Line Numbers
  1.     $password="13abcc";
  2.     if(strlen($password)>=6){
  3.         $number_part=substr($password,0,2);
  4.         $alpha_part=substr($password,2,4);
  5.         if(ereg("[^0-9]",$number_part)){
  6.             $msg="First two characters must be numbers";
  7.         }
  8.         else if(ereg("[^a-zA-Z]",$alpha_part)){
  9.             $msg="Last four characters must be alphabets!";
  10.         }
  11.         else
  12.             $msg="Password is valid!";
  13.     }
  14.     echo $msg;
  15.  
Jun 5 '08 #2
hsriat
1,654 Expert 1GB
Hi All

I Want to validate password,, the condition is that first 2 letters must be numbers and remaining 4 must be alphabets..How can i solve this ????
Or use preg_match with this regular expression.
"/^[0-9]{2}[a-zA-Z]{4}$/"
Jun 5 '08 #3
vikas1111
122 100+
Or use preg_match with this regular expression.
"/^[0-9]{2}[a-zA-Z]{4}$/"


Thanks guys...

I am donig it in javascript so i used the above regular exp.

Thanks for both of you..
Jun 5 '08 #4
hsriat
1,654 Expert 1GB
I am donig it in javascript so i used the above regular exp.
and you asked this question in PHP forum.
Jun 5 '08 #5
vikas1111
122 100+
and you asked this question in PHP forum.

By the way in am actually working in php,, I had to validate a form,, I was looking for reg expr..
Jun 5 '08 #6
Atli
5,058 Expert 4TB
I am donig it in javascript so i used the above regular exp.
Be careful tho. Don't assume the value PHP gets is valid just because Javascript validated it.
It can be easily bypassed and invalid, even malicious, passwords sent.
Jun 5 '08 #7
TheServant
1,168 Expert 1GB
It is best to use both PHP and javascript. have javascript test for invalid characters and if all fields are filled in (front end) and then where ever the form goes you NEED PHP checking to make sure that the input is sanitized.

Basically that way all the javascript is for is to reduce the serverload when normal users (those with javascript enabled) make a mistake filling in the form. The 0.01% of users who purposefully enter in bad data need to be dealt with via PHP validation and sanitation.

Again, I strongly recommend you do it this way as javascript alone is useless for safety.
Jun 5 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Joeri KUMBRUCK | last post by:
Hello, I'm trying to create an ASP page where users can type in a username and password, and these credential should be checked with active directory. If username and password are correct, the...
3
by: arktikturtle | last post by:
Hi! I'm looking for a way to validate a password within PL/SQL. I want to write CREATE PROCEDURE change_password(old_password IN VARCHAR2) IS BEGIN -- check if old_password is correct... but...
2
by: Steffen Balslev | last post by:
I tried to find a way to validate user credentials using C#, searching google and lots of other news and kb sites left me without a solution. You can use a SSPI but it's that easy to implement so...
0
by: Joeri KUMBRUCK | last post by:
Hello, I'm trying to create an ASP page where users can type in a username and password, and these credential should be checked with active directory. If username and password are correct, the...
1
by: Raghuram | last post by:
if i want to validate the LDAP user like i will provide him with the domain name but not the user name and pass when the user enters the user name and pass i should validate towards my domain, and...
3
by: Greg | last post by:
I am trying to figure out how to validate a userid against AD. At the time the user will be logged on as the local admin, right after puuling down a fresh image. the form asks for the userid and...
1
by: Peterwkc | last post by:
hello all expert database administrator, i truly new to access. I want to develop a website where the password and re-enter password must be same. How to i validate this in access or i need ti...
3
by: ojnoka | last post by:
Hi, I am a newbie. I don't know javascript. I use the free javascripts and try to understand them. I have a javascript now, to validate username and password. I paste it below. My question now. Is...
16
by: BlackEye | last post by:
Hi all! i want to validate the user name and password using an sql table i created. i have tried the following code: SqlConnection myConnection = new SqlConnection("data...
5
by: ghjk | last post by:
I have a web site with several web pages. They are having different number of variables. eg: first page having 4 variables in the form(Name, Phone, ID, Gender) second page having 10 variables in the...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.