/    Sign up×
Community /Pin to ProfileBookmark

dontknownuthinboutscriptin

Quick question:
Can the following script be modified to allow multiple users to have individual passwords leading to a specific page for each password?
<form>
<p>Client ID :
<input type=”text” name=”text2″>

Password :
<input type=”password” name=”text1″>
<input type=”button” value=”Log In” name=”Button” onclick=javascript:validate(text2.value,”cwide”,text1.value,”A6rz5″) >
</p>
</form>

<script language = “JavaScript”>

function validate(text1,text2,text3,text4)
{
if (text1==text2 && text3==text4)
load(‘countrywide/base.htm’);
else
{
load(‘HTML_Script/loginfailed.htm’);
}
}
function load(url)
{
location.href=url;
}
</script>

Thanks in advance. ?

ps: I know and do not care that javascript passwords can be hacked by a spider monkey.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterMar 22.2006 — To allow multipul users which are taken to the same page after logining-in, you'd do:
<i>
</i>&lt;script type="text/javascript"&gt;
var authorizedUsers={
"cwide":"A6rz5",
"nextUser1":"nextPassowrd1",
"nextUser2":"nextPassowrd2"
};
&lt;/script&gt;&lt;script type="text/javascript"&gt;
function serveUser(u,p){
if(verifyUser(u,p)){
load('countrywide/base.htm');
}else{
load('HTML_Script/loginfailed.htm');
}
return true;
}
function verifyUser(u,p){return authorizedUsers[u]==p;}
function load(url){location.href=url;}
&lt;/script&gt;


&lt;form&gt;
&lt;p&gt;Client ID :
&lt;input type="text" name="text2"&gt;

Password :
&lt;input type="password" name="text1"&gt;
&lt;input type="button" value="Log In" name="Button" onclick="return serveUser(this.form.text2.value,this.form.text1.value)"&gt;
&lt;/p&gt;
&lt;/form&gt;



If you wanted the user to goto a page like "myUserName/myPassword.htm" you'd do
<i>
</i>&lt;script type="text/javascript"&gt;
var finalPage="&lt;$u&gt;/&lt;$p&gt;.htm";
var authorizedUsers={
"cwide":"A6rz5",
"nextUser1":"nextPassowrd1",
"nextUser2":"nextPassowrd2"
};
&lt;/script&gt;&lt;script type="text/javascript"&gt;
function serveUser(u,p){
if(verifyUser(u,p)){
load(getFinalPage(u,p));
}else{
load('HTML_Script/loginfailed.htm');
}
return true;
}
function verifyUser(u,p){return authorizedUsers[u]==p;}
function getFinalPage(u,p){return finalPage.replace(/&lt;$u&gt;/g,u).replace(/&lt;$p&gt;/g,p);}
function load(url){location.href=url;}
&lt;/script&gt;


&lt;form&gt;
&lt;p&gt;Client ID :
&lt;input type="text" name="text2"&gt;

Password :
&lt;input type="password" name="text1"&gt;
&lt;input type="button" value="Log In" name="Button" onclick="return serveUser(this.form.text2.value,this.form.text1.value)"&gt;
&lt;/p&gt;
&lt;/form&gt;


However since users will be able to just view your page's source and get the password for any user, you'd be advised to not keep a list of users and their passwords in JavaScript and instead redirect them so they can try their luck if the page even exists:
<i>
</i>&lt;form&gt;
&lt;p&gt;Client ID :
&lt;input type="text" name="text2"&gt;

Password :
&lt;input type="password" name="text1"&gt;
&lt;input type="button" value="Log In" name="Button" onclick="location.href=this.form.text2.value+'/'+this.form.text1.value+'.htm'"&gt;
&lt;/p&gt;
&lt;/form&gt;
Copy linkTweet thisAlerts:
@KLQauthorMar 22.2006 — You Sir are a Gentleman, thank you.
×

Success!

Help @KLQ 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.26,
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,
)...