www.webdeveloper.com
Results 1 to 10 of 10

Thread: help me please !!!!

  1. #1
    Join Date
    Jan 2014
    Posts
    3

    Exclamation help me please !!!!

    can someone please help me as I need to code a java script password 3 attempts then locked out help I keep messing up when I did get it to work it looks nothing like the persudo code help me please!!!!

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,377

    Exclamation

    help me please!!!

    Show some code!!!
    Some sort of attempt!!!

  3. #3
    Join Date
    Jan 2014
    Posts
    3
    <html>
    <head>

    <script = "Javascript" >
    //javascript

    //begin
    var valid = false;
    Checkpass(valid) passing valid as parameter
    valid is updated by return value from Checkpass()
    if valid = true
    alert (“password correct");
    else
    display “password incorrect"
    if alert ('enter vaild password')
    //end
    Level 2 (Functions)
    function Checkpass()
    var password= '';
    var count=1;

    prompt ('please input password');
    if (password != '123XY')
    {
    alert ('error message');
    }
    else
    {
    valid=true;
    return(valid)
    }
    count= count + 1;
    while (password != '123XY' && count < 4)



    //end of javascript
    </script>

    </head>
    </html>

  4. #4
    Join Date
    Jan 2014
    Posts
    3

    Exclamation help im a beginner !!!

    Quote Originally Posted by JMRKER View Post
    help me please!!!

    Show some code!!!
    Some sort of attempt!!!
    <html>
    <head>

    <script = "Javascript" >
    //javascript

    //begin
    var valid = false;
    Checkpass(valid) passing valid as parameter
    valid is updated by return value from Checkpass()
    if valid = true
    alert (“password correct");
    else
    display “password incorrect"
    if alert ('enter vaild password')
    //end
    Level 2 (Functions)
    function Checkpass()
    var password= '';
    var count=1;

    prompt ('please input password');
    if (password != '123XY')
    {
    alert ('error message');
    }
    else
    {
    valid=true;
    return(valid)
    }
    count= count + 1;
    while (password != '123XY' && count < 4)



    //end of javascript
    </script>

    </head>
    </html>

  5. #5
    Join Date
    Oct 2012
    Location
    Croatia
    Posts
    255
    Quote Originally Posted by guitarkitten View Post
    var valid = false;
    Checkpass(valid) passing valid as parameter
    valid is updated by return value from Checkpass()
    if valid = true
    alert (“password correct");
    else
    display “password incorrect"
    if alert ('enter vaild password')
    //end
    Level 2 (Functions)
    function Checkpass()
    var password= '';
    var count=1;
    Is this supposed to be a pseudocode or actual JavaScript code?
    If this is your JS code, not the pseudocode then almost every written line of it is wrong.
    Last edited by tech_soul8; 01-29-2014 at 04:40 PM.

  6. #6
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,346
    You should not use JavaScript to authenticate passwords.

    This should be done with a database and PHP.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  7. #7
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,377

    Lightbulb

    Major re-write of your code ahead. Too many mistakes to count...

    Couple of comments first:
    1. Not a good idea to write passwords into JS as it just takes a 'view source' to read them.
    2. Prompt is not the best way to collect the password information. Consider using an <input type="text" ...>
    3. Review your books or tutorials to see how to write comments into your code.
    4. Most programmers start the count from zero to represent no attempts have occured.
    It will prove helpful to you to know this when you start to play with array elements.
    5. alert(msg) is OK for testing, but you should consider a different method to inform the user of problems or success.
    6. If you plan on passing this off as your own code to an instructor, be prepared to defend it and the logic.
    7. For the forum members you should enclose your script betwee [ code] and [ /code] tags (without the spaces).

    Code:
    <html>
    <head>
    </head>
    <body>
    <div id="debug"></div>
    
    <script type="text/javascript" >
    //javascript begin
    /*
    var valid = false;
    Checkpass(valid) passing valid as parameter
    valid is updated by return value from Checkpass()
    if valid = true
    alert (“password correct");
    else
    display “password incorrect"
    if alert ('enter vaild password')
    //end
    Level 2 (Functions)
    */
    
    function Checkpass() {
      var valid = false;
      var password= '';
      var count=0;
      while (valid == false && count < 3) {
        password = prompt('please input password');
        if (password != '123XY') { count++; alert ('Attempt #'+count+' incorrect'); }
                            else { return true; }
      }
      return false;
    }
    window.onload = function() {
      var str = '';
      if (Checkpass()) { 
    //  success code placed here
        str = 'Correct password entered';
      } else {
        str = 'You lose:  3 attempts at password fail';
      }
       document.getElementById('debug').innerHTML = str;
    }
    
    //end of javascript
    </script>
    
    </body>
    </html>

  8. #8
    Join Date
    Jun 2009
    Posts
    18
    It can be only done with js+php and a key database if you are going to use multiple passwords. If you are interested in, I can send you some sample files.
    Last edited by Flashbond; 01-30-2014 at 06:45 AM.

  9. #9
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,648
    ...Or if I was a scholar and could handle a pen
    One secret love letter to my true love I'd send
    And I'd tell of my sorrow, my grief and my pain
    Since she's gone and left me in yon flowery glen...
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

  10. #10
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,346
    Does the server you are working on have an Apache Web server installed?

    If so, you could take advantage of http://httpd.apache.org/docs/2.2/howto/auth.html

    By default login attempts should be limited to 3 attempts then an error page displayed.

    Job done, no javascipt needed and its secure.
    Last edited by \\.\; 01-30-2014 at 08:05 PM.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles