Javascript log-in
A Flash Developer Resource Site

Results 1 to 20 of 20

Thread: Javascript log-in

  1. #1
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    912

    Javascript log-in

    I know that the best way to make a log-in is by using PHP, but since I still don't have an FTP program (please don't give me links or anything, only pay attention to my questions please), I can't use it. I want the javascript to validate one textfield (for now, since I can add a password one later). I have an array of the usernames, and what I did was use a for statement to go to let's say 100, then in the for statement I had an if statement, which basically says:

    for (i=0,i<=100,i++) {
    if (textFieldName==myArray[i]) {
    alert("Welcome")
    } else {
    alert("Wrong")
    }
    }

    It doesn't work, and I don't know why. I'm knew to javascript, so it would be awsome if you ppl could help me!
    WIP-ZOMBIES

    I love vegetarians! More meat for the rest of us!

  2. #2
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    I might use an object instead of an array, it'll save on the looping. Here's an example:

    Code:
    <html>
    <head>
    <script type="text/javascript">
    onload = function() {
        // setup the list of valid usernames
        var users = {
           "pazil": 1,
           "catbert303": 1,
           "some_other_user": 1
        };
        // have the script check if the username entered is valid when the user leaves the textfield
        document.getElementById('username').onblur = function() {
            // if the value in the textfield is in the users lookup object then they entered a correct name
            if (users[this.value]) {
                alert('welcome');
            } else {
                alert('wrong');
            }
        };
    };
    </script>
    </head>
    <body>
    
    <input type="text" id="username" value="">
    
    </body>
    </html>

  3. #3
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    912
    OK, thanks! I still have 3 questions. Why do the var names have : 1, at the end? And how would I attach a password to each username? Also, the reason I wanted to use an array, was then for registry, I just add their wanted username and password to the two username and password arrays, then it saves the javascript file...So how would I make a registry for this way? Thanks alot though!
    WIP-ZOMBIES

    I love vegetarians! More meat for the rest of us!

  4. #4
    Senior Member
    Join Date
    Jan 2005
    Posts
    1,582
    You realize that all the user has to do is check source on the page and they'll know the login, yes?

  5. #5
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    the 1's are there simply so that when the property is checked in the lookup table it is found to exist.

    If you want to add passwords to this (again remembering that this offers zero security!) you would replace the 1's with the passwords for the individual usernames, here's a very quick example:

    Code:
    <html>
    <head>
    <script type="text/javascript">
    onload = function() {
        // setup the list of valid usernames
        var users = {
           "pazil": "password",
           "catbert303": "another password",
           "some_other_user": "wow, would you look at that - a password"
        };
    
        document.getElementById('login').onclick = function() {
            var user = document.getElementById('username').value;
            var pass = document.getElementById('password').value;
    
            // if the value entered for the username exists in the lookup table and the password entered matches the password for that user...
            if (users[user] && users[user] == pass) {
                alert('welcome');
            } else {
                alert('wrong');
            }
        };
    };
    </script>
    </head>
    <body>
    
    Username: <input type="text" id="username" value=""><br>
    Password: <input type="password" id="password" value=""><br>
    <input type="button" id="login" value="Login">
    
    </body>
    </html>

  6. #6
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    912
    Thank-you so much! Do I NEED to use PHP to make a registry? Also, for security, can't I just link the js file to this document? THANK-YOU!
    WIP-ZOMBIES

    I love vegetarians! More meat for the rest of us!

  7. #7
    FK's Official Mac Hater jasonsplace's Avatar
    Join Date
    Mar 2002
    Location
    Provo, Utah
    Posts
    2,245
    Quote Originally Posted by Pazil
    Thank-you so much! Do I NEED to use PHP to make a registry? Also, for security, can't I just link the js file to this document? THANK-YOU!
    No. That code is still accessible to the end user. JavaScript is done client side and anything client side can be seen. To do it secure you'll have to use server side technology like ASP or PHP.
    Jason L. Wright
    I'm not that hard to imitate. Just make some random negative claim at Apple or anything else for that matter and then have nothing to back it up.

  8. #8
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    912
    oh...but can I still do registry?
    WIP-ZOMBIES

    I love vegetarians! More meat for the rest of us!

  9. #9
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Sorry, I'm not sure what you mean by "registry"?

  10. #10
    FK's Official Mac Hater jasonsplace's Avatar
    Join Date
    Mar 2002
    Location
    Provo, Utah
    Posts
    2,245
    If you mean registration then No, JavaScript can't save anything on the server without some kind of server side language helping it.
    Jason L. Wright
    I'm not that hard to imitate. Just make some random negative claim at Apple or anything else for that matter and then have nothing to back it up.

  11. #11
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    912
    ok...rats...I was hoping I could get myself out of learning PHP, and use JavaScript...oh well, thanks for all your help!!!
    WIP-ZOMBIES

    I love vegetarians! More meat for the rest of us!

  12. #12
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    912
    jasonsplace, could you help me with PHP?
    WIP-ZOMBIES

    I love vegetarians! More meat for the rest of us!

  13. #13
    FK's Official Mac Hater jasonsplace's Avatar
    Join Date
    Mar 2002
    Location
    Provo, Utah
    Posts
    2,245
    What kind of PHP help do you need?
    Jason L. Wright
    I'm not that hard to imitate. Just make some random negative claim at Apple or anything else for that matter and then have nothing to back it up.

  14. #14
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    912
    well...bascially learning the code. I tried to learn PHP at w3schools.com, which was pretty useful, except...I can't try it out, since I don't have an FTP program...
    WIP-ZOMBIES

    I love vegetarians! More meat for the rest of us!

  15. #15
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    912
    Well, exactly for the help, I guess I just might ask questions once in a while...
    WIP-ZOMBIES

    I love vegetarians! More meat for the rest of us!

  16. #16
    FK's Official Mac Hater jasonsplace's Avatar
    Join Date
    Mar 2002
    Location
    Provo, Utah
    Posts
    2,245
    You only need an FTP program if you have a server somewhere that supports PHP. To test on your local computer install WAMP.
    Jason L. Wright
    I'm not that hard to imitate. Just make some random negative claim at Apple or anything else for that matter and then have nothing to back it up.

  17. #17
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    912
    Ok, kewl! Thanx again!
    WIP-ZOMBIES

    I love vegetarians! More meat for the rest of us!

  18. #18
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    912
    And did you get that mac video I sent you a while ago?
    WIP-ZOMBIES

    I love vegetarians! More meat for the rest of us!

  19. #19
    FK's Official Mac Hater jasonsplace's Avatar
    Join Date
    Mar 2002
    Location
    Provo, Utah
    Posts
    2,245
    I did. It was pretty funny.
    Jason L. Wright
    I'm not that hard to imitate. Just make some random negative claim at Apple or anything else for that matter and then have nothing to back it up.

  20. #20
    Senior Member Pazil's Avatar
    Join Date
    Sep 2006
    Location
    Ontario, Canada
    Posts
    912
    "You idiot! You own a Macintosh! The file is ****ing gone! It's just gone!" That's my favourite part...anyways, cya all, and thanx for all the help ppl!!! I'll most likely post again in this forum with some other problem I have in Javascript...cya!
    WIP-ZOMBIES

    I love vegetarians! More meat for the rest of us!

Posting Permissions

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




Click Here to Expand Forum to Full Width


HTML5 Development Center

Poll by Flashkit.com