Current location: Hot Scripts Forums » General Web Coding » JavaScript » RE: Login redirect script


RE: Login redirect script

Reply
  #1 (permalink)  
Old 02-25-09, 04:22 AM
duranross duranross is offline
Newbie Coder
 
Join Date: Jan 2009
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Spin RE: Login redirect script

Hi guys, i really need help for this script: what I want is a log-in script that redirects the user to a different href depending on what username/password they entered, so e.g. - username1 will go to page1 and username2 to page 2, etc...

If preferable all the username/passwords would be stored on a text file or something so all pages that use the details don't need to be updated every time a new user is needed to be added.

So far I have this....


HTML Code:
<script type="text/javascript">

function verify(menu,pass){
	
	var setpass = "a";

	var lowpass = pass.toLowerCase();

	if(menu == "alex" && lowpass == "one"){
		window.location.href = "Alex_main.html"; 
	}
	
	if(menu == "bob" && lowpass == "two"){
	window.location.href = "Bob_main.html"; 
	}
	
	if(menu == "cat" && lowpass == "three"){
	window.location.href = "Cat_main.html"; 
	}

	else{
	window.location.href = "error.html"; 
	}
}
</script>



<form name="LogIn1" method="post">

		<table>
			<tr>
				<td>
				
				
				
				<input name="URLselect" size="12" />
				
				
				
				</td>

			</tr>
			<tr>
				<td><input type="password" name="pwdPassword" size="12" /></td>
			</tr>
			<tr>
				<td><input type="button" onClick="verify(document.LogIn1.URLselect.value,document.LogIn1.pwdPassword.value)" value="Log in" /></td>
			</tr>
		</table>
	</form>

However, for the first username - it doesn't seem to work on occasion and redirects to the error page instead of the href! Can anyone see why this would be?

Hope someone can help me!

Thanks in advance!
Reply With Quote
  #2 (permalink)  
Old 02-25-09, 05:39 AM
Yeroon's Avatar
Yeroon Yeroon is offline
Code Master
 
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
You should probably use else if. If you type a capital letter in the username, a wrong username pass combi, only then it will go to the else. See what happens if you use this:

Code:
<script type="text/javascript">

function verify(menu,pass){
	
	var setpass = "a";
	var lowpass = pass.toLowerCase();

	if(menu == "alex" && lowpass == "one"){
		window.location.href = "Alex_main.html"; 
	}
	else if(menu == "bob" && lowpass == "two"){
	window.location.href = "Bob_main.html"; 
	}
	else if(menu == "cat" && lowpass == "three"){
	window.location.href = "Cat_main.html"; 
	}
	else{
	window.location.href = "error.html"; 
	}
}
</script>



<form name="LogIn1" method="post">

		<table>
			<tr>
				<td>
				
				
				
				<input name="URLselect" size="12" />
				
				
				
				</td>

			</tr>
			<tr>
				<td><input type="password" name="pwdPassword" size="12" /></td>
			</tr>
			<tr>
				<td><input type="button" onClick="verify(document.LogIn1.URLselect.value,document.LogIn1.pwdPassword.value)" value="Log in" /></td>
			</tr>
		</table>
	</form>
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
Reply With Quote
  #3 (permalink)  
Old 02-25-09, 05:58 AM
duranross duranross is offline
Newbie Coder
 
Join Date: Jan 2009
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks - that works now! Very much appreciated. Any way to the do the saving of the passwords into the text file thingi... thanks!
Reply With Quote
  #4 (permalink)  
Old 02-25-09, 06:35 AM
Yeroon's Avatar
Yeroon Yeroon is offline
Code Master
 
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
Is this done after login or should the credentials be checked by above code against this textfile too? The way things are setup with above code everyone can always read the usernames and passwords from the page source.
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
Reply With Quote
  #5 (permalink)  
Old 02-25-09, 10:10 AM
duranross duranross is offline
Newbie Coder
 
Join Date: Jan 2009
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Yes, i understand that at the moment people can view the usernames which is why I want to change this... I don't really know much about javascript, sorry!!!

I basically have the log-in script on the header of all my .html pages - the user logs in, and then they are forwarded to a different website according to which username/password they enter.

So: can i get the script to read from a .txt file or something?

Thanks!
Reply With Quote
  #6 (permalink)  
Old 02-25-09, 10:42 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
It's possible to do this using XMLHttpRequest()s, but it will only make a little bit more secure. It'll still be very easy to see all user names and passwords.

Your best and most secure bet is using a server side script, written in for example PHP and MySQL.
Reply With Quote
  #7 (permalink)  
Old 02-25-09, 10:50 AM
duranross duranross is offline
Newbie Coder
 
Join Date: Jan 2009
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Security is not an issue really - it is just for customers to log in after attending an event and to be forwarded to the correct image gallery. How would i go about XMLHttpRequest'ing?

Sorry for all the annoying questions...
Reply With Quote
  #8 (permalink)  
Old 03-07-09, 05:47 AM
duranross duranross is offline
Newbie Coder
 
Join Date: Jan 2009
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
bump........
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto Login Script Required rashish12 Script Requests 7 08-31-09 09:30 AM
login script chazze06 PHP 13 12-29-08 11:21 PM
login script works fine in firefox, nothing in IE! varial PHP 3 03-14-05 08:36 AM
Login Script barnkin PHP 4 03-01-05 07:39 PM
Redirect previous 2 pages after login mcrob PHP 5 01-01-05 07:35 AM


All times are GMT -5. The time now is 11:46 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.