-
Senior Member
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!
-
Senior Member
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>
-
Senior Member
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!
-
You realize that all the user has to do is check source on the page and they'll know the login, yes?
-
Senior Member
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>
-
Senior Member
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!
-
FK's Official Mac Hater
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.
-
Senior Member
oh...but can I still do registry?
WIP-ZOMBIES
I love vegetarians! More meat for the rest of us!
-
Senior Member
Sorry, I'm not sure what you mean by "registry"?
-
FK's Official Mac Hater
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.
-
Senior Member
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!
-
Senior Member
jasonsplace, could you help me with PHP?
WIP-ZOMBIES
I love vegetarians! More meat for the rest of us!
-
FK's Official Mac Hater
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.
-
Senior Member
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!
-
Senior Member
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!
-
FK's Official Mac Hater
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.
-
Senior Member
WIP-ZOMBIES
I love vegetarians! More meat for the rest of us!
-
Senior Member
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!
-
FK's Official Mac Hater
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.
-
Senior Member
"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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|