1

So I have a login script I made but I want it so when a user logins in successfully they go to a page set for that said user for example that users profile page How would I achieve this?

<script type = "text/javascript">
var count = 2;
function validate() {
 var un = document.myform.username.value;
 var pw = document.myform.pword.value;
 var valid = false;
 var unArray = ["Philip", "George", "Sarah", "Michael"];
 var pwArray = ["Password1", "Password2", "Password3", "Password4"];
 for (var i=0; i <unArray.length; i++) {
 if ((un == unArray[i]) && (pw == pwArray[i])) {
 valid = true;
 break;
 }
 }
 if (valid) {
 alert ("Login was successful");
 window.location = "http://www.google.com";
 return false;
 }
 var t = " tries";
 if (count == 1) {t = " try"}
 if (count >= 1) {
 alert ("Invalid username and/or password. " +
 "You have " + count + t + " left.");
 document.myform.username.value = "";
 document.myform.pword.value = "";
 setTimeout("document.myform.username.focus()", 25);
 setTimeout("document.myform.username.select()", 25);
 count --;
 }
 else {
 alert ("Still incorrect! You have no more tries left!");
 document.myform.username.value = "No more tries allowed!";
 document.myform.pword.value = "";
 document.myform.username.disabled = true;
 document.myform.pword.disabled = true;
 return false;
 }
}
</script>
<form name = "myform">
 <p>
 ENTER USER NAME <input type="text" name="username">
 ENTER PASSWORD <input type="password" name="pword">
 <input type="button" value="Check In" name="Submit" onclick="validate()">
 </p>
</form>
Mörre
5,7536 gold badges41 silver badges68 bronze badges
asked Nov 24, 2013 at 9:05
4
  • 2
    What is the "BLAH..." part? Commented Nov 24, 2013 at 9:06
  • What is your problem! What do you mean Blah ?! Commented Nov 24, 2013 at 9:15
  • not really sure what you are asking, but you should be doing password validation server side, not in javascript. Look on google for some examples Commented Nov 24, 2013 at 9:15
  • Could you describe your environment - which web framework are you using? Commented Nov 24, 2013 at 9:30

3 Answers 3

1

First I can't answer this without stating that Philip, George, Sarah or Michael wont thank you for making their passwords visible in this way:

var pwArray = ["Password1", "Password2", "Password3", "Password4"];

As others have said: If you were to code a page like this there is no point in using passwords as they would be visible to all users of the page. However given the method you have used so far, you could do the following

var pwLocation = ["location1", "location2", "location3", "location4"];
window.location = pwLocation[i];
answered Nov 24, 2013 at 9:21
Sign up to request clarification or add additional context in comments.

Comments

0

Creating Login page using javascript is not secure because since javascript is client side scripting, any user can see what the code looks like using the page source, so if you need to make login pages you better learn Server side scripting languags like PHP.

To answer you question :

Use if statment to redirect each user to specific page based on their user name , for example if username is 'jamson' then redirect jamson to his own page using the location where his page is found. still this method is ardous if you have thousandth of users.

answered Nov 24, 2013 at 9:14

Comments

0

I wouldn't do this via JavaScript. It's highly insecure as users can view-source, and can find a list of usernames.

To answer your question though, change the line that says: window.location = "http://www.google.com";, to window.location = un.toLowerCase()+".html";.

answered Nov 24, 2013 at 9:21

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.