Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Login Information within a URL

Status
Not open for further replies.

jasonray

MIS
Apr 5, 2002
15
US
I need some help. To start out, I just strated learning Javascript about a week ago, and I am starting to understand it as the days go on. My question is this, I need to pass a User Name and Password throught the URL. Now I know this is easy with some URL's, but I seem to be having a hard time with it.

"
So far I have writen a javascript function to create the URL in the format that it needs to be.

function logon(){
var url = " + document.form2.username.value ;
url += "&Password=" + document.form2.password.value ;
document.url=;

This is about as far as I can get. If I use "alert(acct);" at the end of the function, I get a pop-up with the correct format and anything. What I really need help with is, How do I launch this URL?

Sorry if I dont make sense.

Thank you,

Jason Ray
 
The following will do what you want:

function logon(){
var url = " + document.form2.username.value ;
url += "&Password=" + document.form2.password.value ;
location.href=url;
}


However, did you realize that the login name and password will be visible then in the URL when it switches pages? Is this what you wanted? If you're using ASP to process the information, you should use method=post in the form tag, and then in your asp page:

username=Request("username") & ""
password=Request("password") & ""

to get the values without exposing them to anyone walking by.
 
If you have a form for accepting the user entry of username and password, you may not actually have to create the string like above, instead set the form method to GET and the information from the form will instead be placed into the querystring like you have built above. For instance:
Code:
<form action=&quot;logon.asp&quot; method=&quot;GET&quot;>
<input type=&quot;hidden&quot; name=&quot;CMD&quot; value=&quot;LOGON&quot;>
<input type=&quot;text&quot; name=&quot;UserName&quot;>
<input type=&quot;password&quot; name=&quot;Password&quot;>
<input type=&quot;submit&quot; value=&quot;Login!&quot;>
</form>
When the user hits select this will send to the logon.asp with the URL
logon.asp?CMD=LOGON&UserName=whatTheyTyped&Password=WhatTheyTyped

Which you can then get back on the next page with Request.QueryString

If you do have to generate and run that URL as above (in the case that my initial estimation was way off :) )
Than you could use window.location = url

-Tarwn The three most dangerous things in the world are a programmer with a soldering iron, a hardware type with a program patch, and a user with an idea
-computer saying (Wiz Biz - Rick Cook)
 
Thank you for your help. That worked. To answer your question about the username and password showing in the url, once the url gets passed, the person gets redirected to proper page. Thanks again.

Jason Ray
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top