/    Sign up×
Community /Pin to ProfileBookmark

symbols, numbers, lower case and upper case letters in passwords

I have a client that needs to have passwords check for the following:

8 characters long
at least one symbol
at least one lower case letter
at lesat one upper case letter
at least one number.

Can anyone lead me in the right direction on how to do this? Just looking around on the net I came up with this:

[code]
<script language=”javascript”>

function validatepass() {
var mypass1 = document.frmLogin.txtPass1.value;
var mypass2 = document.frmLogin.txtPass2.value;

var lowerC = /[a-z]/;
var upperC = /[A-Z]/;
var numbers = /[0-9]/;
var symobls = /[!@#$%^&*()<>?~`-_=+/;

var isgood = true;
var myMessage = “You must follow all required criteria for passwords:n”;

if (!lowerC.test(mypass1)) {
isgood = false;
myMessage += ” One Lower Case letter.n”;
}

if (!upperC.test(mypass1)) {
isgood = false;
myMessage += ” On Upper Case letter.n”;
}

if (!numbers.test(mypass1)) {
isgood = false;
myMessage += ” One Number (0-9).n”;
}

if (!symbols.test(mypass1)) {
isgood = false;
myMessage += ” One Symbol.n”;
}

if (mypass1.length() < 8) {
isgood = false;
myMessage += ” Length must be equal to or longer than 8 characters.n”;
}

if (mypass1 <> mypass2) {
isgood = false;
myMessage += ” Both passwords MUST match!n”;
}

if (isgood == false) {
alert(myMessage);
return false;
} else {
return true;
}
}
</script>
[/code]

But I’m not sure if it will work yet… am I close?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@CharlesSep 20.2006 — [font=monospace]var symobls = /[!@#$%^&*()<>?~`-_=+/;[/font] might be better written as var symobls = /W/;[/font] and [font=monospace]if (isgood == false)[/font] as [font=monospace]if (!isgood)[/font]. But other than that give it a try to see.
Copy linkTweet thisAlerts:
@djanim8authorSep 20.2006 — ok I did that with the /W thing...

<i>
</i>&lt;script language="JavaScript"&gt;
&lt;!--
function validatepass()
{
var mypassA = document.frmLogin.txtPass1.value;
var mypassB = document.frmLogin.txtPass2.value;
alert (mypassA + " - " + mypassB)
var lowerC = /[a-z]/;
var upperC = /[A-Z]/;
var numbers = /[0-9]/;
var symbs = /W/;

<i> </i> var isgood = true;
<i> </i> var myMessage = "You must follow all required criteria for passwords:n";

<i> </i> if (!lowerC.test(mypassA)) {
<i> </i> isgood = false;
<i> </i> myMessage += " One Lower Case letter.n";
<i> </i> }

<i> </i> if (!upperC.test(mypassA)) {
<i> </i> isgood = false;
<i> </i> myMessage += " On Upper Case letter.n";
<i> </i> }

<i> </i> if (!numbers.test(mypassA)) {
<i> </i> isgood = false;
<i> </i> myMessage += " One Number (0-9).n";
<i> </i> }

<i> </i> if (!symbs.test(mypassA)) {
<i> </i> isgood = false;
<i> </i> myMessage += " One Symbol.n";
<i> </i> }

<i> </i> if (mypassA.length &lt; 8) {
<i> </i> isgood = false;
<i> </i> myMessage += " Length must be equal to or longer than 8 characters.n";
<i> </i> }

<i> </i> if (mypassA &lt;&gt; mypassB) {
<i> </i> isgood = false;
<i> </i> myMessage += " Both passwords MUST match!n";
<i> </i> }

<i> </i> if (!isgood) {
<i> </i> alert(myMessage);
<i> </i> return false;
<i> </i> } else {
<i> </i> alert("All Good!");
<i> </i> return true;
<i> </i> }
<i> </i>}
--&gt;
&lt;/script&gt;


but it gives me errors on this part:
<i>
</i> if (mypassA &lt;&gt; mypassB) {
isgood = false;
myMessage += " Both passwords MUST match!n";
}


the mypassA is a text field that has the first password in it, then mypassB is to varify that the passwords are the same (second text box) but it gives me errors on that part...
Copy linkTweet thisAlerts:
@CharlesSep 20.2006 — if (mypassA != mypassB)
×

Success!

Help @djanim8 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...