/    Sign up×
Community /Pin to ProfileBookmark

Modifying password script

Hello , I’m only new to javascript.
I was wondering if it’s possible to modify the ‘Multiple Users Login Table’ script to have 3 tries and then redirect with it as well ?

[url]http://javascript.internet.com/passwords/multiple-users-source.html[/url]

<!– TWO STEPS TO INSTALL MULTIPLE USERS:

  • 1. Copy the first code into the HEAD of your HTML document

  • 2. Put the last coding into the BODY of your HTML document –>
  • <!– STEP ONE: Copy this code into the HEAD of your login HTML document –>

    <HEAD>

    <SCRIPT LANGUAGE=”JavaScript”>

    <!– This script and many more are available free online at –>
    <!– The JavaScript Source!! [url]http://javascript.internet.com[/url] –>

    <!– Begin
    function Login(){
    var done=0;
    var username=document.login.username.value;
    username=username.toLowerCase();
    var password=document.login.password.value;
    password=password.toLowerCase();
    if (username==”member1″ && password==”password1″) { window.location=”page1.html”; done=1; }
    if (username==”member2″ && password==”password2″) { window.location=”page2.html”; done=1; }
    if (username==”member3″ && password==”password3″) { window.location=”page3.html”; done=1; }
    if (done==0) { alert(“Invalid login!”); }
    }
    // End –>
    </SCRIPT>

    <!– STEP TWO: Paste this code into the BODY of your HTML document –>

    <BODY>

    <center>
    <form name=login>
    <table width=225 border=1 cellpadding=3>
    <tr><td colspan=2><center><font size=”+2″><b>Members-Only Area!</b></font></center></td></tr>
    <tr><td>Username:</td><td><input type=text name=username></td></tr>
    <tr><td>Password:</td><td><input type=text name=password></td></tr>
    <tr><td colspan=2 align=center><input type=button value=”Login!” onClick=”Login()”></td></tr>
    </table>
    </form>
    </center>

    <p><center>
    <font face=”arial, helvetica” size=”-2″>Free JavaScripts provided<br>
    by <a href=”http://javascriptsource.com”>The JavaScript Source</a></font>
    </center><p>

    <!– Script Size: 1.60 KB –>

    Any help would be appreciated.
    I’m not concerned about security of the script as its just for learning and fun.

    to post a comment
    JavaScript

    9 Comments(s)

    Copy linkTweet thisAlerts:
    @daveyOct 21.2004 — [code=php]<SCRIPT LANGUAGE="JavaScript">
    function Login(){
    var tries=0;
    if(tries<=3){

    var done=0;
    var username=document.login.username.value;
    username=username.toLowerCase();
    var password=document.login.password.value;
    password=password.toLowerCase();
    if (username=="member1" && password=="password1") { window.location="page1.html"; done=1; }
    if (username=="member2" && password=="password2") { window.location="page2.html"; done=1; }
    if (username=="member3" && password=="password3") { window.location="page3.html"; done=1; }
    if (done==0) { alert("Invalid login!");tries++; }
    }
    if (tries>3){
    window.location="failedtologinpage.html";}
    }
    </SCRIPT>[/code]

    //*EXPLANATION*

    in the begining i put a variable that will keep track of the number of times the user has tried to login

    var tries=0;

    the next thing i added was an if statement that checks to see if the user has tried three times

    if(tries<=3){


    the next thing was an increment to tries when the user fails to login

    tries++;

    the last thing was an if statement to move the user to the failed login page after they have failed three times

    if (tries>3){window.location="failedtologinpage.html";}
    Copy linkTweet thisAlerts:
    @jbotOct 21.2004 — worthless ...

    if the user has JS disabled, they'll still be able to access your content :rolleyes:
    Copy linkTweet thisAlerts:
    @heywire01authorOct 21.2004 — Thanks for your help , I figured it out ?

    <html>

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

    <title>Members Area</title>

    <script type="text/javascript">

    var count = 0;

    function Login()

    {

    count++;

    if (count > 3)

    {

    alert("You have failed to login 3 times");

    window.location="denied.html";

    } else {

    var done=0;

    var username=document.login.username.value;

    username=username.toLowerCase();

    var password=document.login.password.value;

    password=password.toLowerCase();

    if (username=="member1" && password=="password1") { window.location="page1.html"; done=1; }

    if (username=="member2" && password=="password2") { window.location="page2.html"; done=1; }

    if (username=="member3" && password=="password3") { window.location="page3.html"; done=1; }

    if (done==0) { alert("Invalid login!"); }

    }

    if (login==false)

    {

    alert("Invalid login! Please Try again. You have " + (3 - count) + " tries left.");

    }

    }

    </script>

    </head>

    <body>

    <BODY>

    <center>

    <form name=login>

    <table width=225 border=1 cellpadding=3>

    <tr><td colspan=2><center><font size="+2"><b>Members-Only Area!</b></font></center></td></tr>

    <tr><td>Username:</td><td><input type=text name=username></td></tr>

    <tr><td>Password:</td><td><input type=password name=password></td></tr>

    <tr><td colspan=2 align=center><input type=button value="Login!" onClick="Login()"></td></tr>

    </table>

    </form>

    </center>

    </body>

    I had to modify bits and pieces but it works , well close enough , It actually gives 4 attempts.

    Thanx again ppl ?
    Copy linkTweet thisAlerts:
    @daveyOct 22.2004 — set the thing >=3
    Copy linkTweet thisAlerts:
    @heywire01authorOct 23.2004 — Thanx for that ?
    Copy linkTweet thisAlerts:
    @steelersfan88Oct 23.2004 — [i]Originally posted by jbot [/i]

    [B]worthless ...



    if the user has JS disabled, they'll still be able to access your content :rolleyes: [/B]
    [/QUOTE]
    It is true, but you haven't expressed the effects of the point clearly.

    If the user has JS disabled, the user will not be able to have his form validated, and correct or not, will be linked to the hidden page. Some sort of server side script in PHP would have to be done ...
    Copy linkTweet thisAlerts:
    @jbotOct 23.2004 — [i]Originally posted by steelersfan88 [/i]

    [B]It is true, but you haven't expressed the effects of the point clearly.[/B][/QUOTE]


    i know, i was being lazy :rolleyes:
    Copy linkTweet thisAlerts:
    @JRichJan 20.2005 — Where do I store the user names & passwords?... how do I enter them?... its a great script but they left out those important details... can anyone offer me any help???
    Copy linkTweet thisAlerts:
    @daveyJan 21.2005 — to have more passwords/names copy and paste the
    [code=php]if (username=="member1" && password=="password1") { window.location="page1.html"; done=1; }
    [/code]
    and edit it accordingly
    ×

    Success!

    Help @heywire01 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 6.5,
    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: @meenaratha,
    tipped: article
    amount: 1000 SATS,

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

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