/    Sign up×
Community /Pin to ProfileBookmark

pass generation regex

Hello,

I want to write a program.

in the program i need to generate a password that contain 8 – 10 charachters.
i did it, but without regex, Can any one help me, how to do this with the regular exp ?

the criterias for the pass are:
1- the length 8 -10 chars.
2- the pass must contain just [a-z] or [A-Z] or [0-9].
3- i must use the char just once in the all pass

sorry for myweak eng
I hope that u understand me, and i hope that u help me.

thank u ?

TiTo

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@NatdripAug 22.2011 — RegExp Object

A regular expression is an object that describes a pattern of characters.

Regular expressions are used to perform pattern-matching and "search-and-replace" functions on text.

It is not used to generate random characters.
Copy linkTweet thisAlerts:
@titosdauthorAug 22.2011 — Yes, exactly

I write the code.

[CODE]
<html>
<head>
<title>password generaton</title>
</head>
<BODY>

<SCRIPT LANGUAGE="JavaScript">

function randomPassword()
{
var repeats = /(.)1/;
var length = randomFromTo(8,12);
chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
pass = "";
for(x=0;x<length;x++)
{
i = Math.floor(Math.random() * 62);
pass += chars.charAt(i);
}
if(repeats.test(pass)){
randomPassword();
}
return pass;
}

function formSubmit()
{
passform.passbox.value = randomPassword();
return false;
}

function randomFromTo(from, to){
return Math.floor(Math.random() * (to - from + 1) + from);
}

// End -->
</script>

<table align="center" border="1">
<tr>
<td valign="middle" align="center">
<center>Random Password Generator</center>
<form name="passform">

Password: <input name="passbox" type="text" size="50" tabindex="1"></p>
<p>
<input type="button" value="Generate" onClick="javascript:formSubmit()" tabindex="2"> <input type="reset" value="Clear" tabindex="3"></p>
</form>
</td>
</tr>
</table>
</html>
[/CODE]


but it doesn't work, it's check if the are two cahrs repeating, i.g if the pass is hello, so can to match it.


but i want to check all the pass not only every two chars

i.g: welcome, i want to match it because it's contains the lchar "e" more than once.
Copy linkTweet thisAlerts:
@DracoMerestAug 23.2011 — If you want only a random password generator it is relatively simple in JavaScript.

However, validating a password of exactly 8 [I]unique[/I] alpha-numeric characters

using regEx is very difficult or lengthy. (both)

The best way to achieve what you have attempted above is to limit each character

choice before it is added to the string. You could do this by randomly removing each

chosen character from the source string list and therefore leaving only unchosen

characters.

Or, as each random character is chosen, check to see if it already exists in the

password. If it does exist, loop and choose another character.

allChrs=" abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
pass="";
r=0;
while(pass.length&lt;8)
{ while(pass.indexOf(allChrs[r])&gt;=0 || r==0)
r=Math.floor(Math.random()*allChrs.length);
pass+=allChrs[r];
};
×

Success!

Help @titosd 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.4,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...