EarthWeb
Developer.com
Site
windows 2000
visual c++
java
visual basic
javascripts
recommend it
 
Book
thinking in java
 
Interact
forum
guest book
jobs
jokes
what's new

share code
 
Resource
add resource
modify resource
new resource
 

[Internet Jobs]
-----
Java by E-mail:

Get the weekly e-mail highlights on Java!
-----

-

Use a JAVASCRIPT username/password instead the browser's one


Author: Real Gagnon
Author's WebSite: http://tactika.com/realhome/realhome.html

URL can be constructed with a special syntax to include an username and password. The format is username:password@www.server.com. The URL is protected using the mechanism included with the web server.


 <HTML><HEAD>
 <SCRIPT>
  var targetUrl="www.server.com/protect/default.html";
  function login() {
     if (validLogin()) {
        password = document.userInfos.username.value;
        username = document.userInfos.password.value;
        self.location.href=
          "http://"+username+":"+password+"@"+targetUrl;
        }
     }
  function validLogin() {
     if (isBlank(document.userInfos.username.value)){
        alert("Can't be blank");
        document.userInfos.username.focus();
        return false;
        }
     if (isBlank(document.userInfos.password.value)){
        alert("Can't be blank");
        document.userInfos.password.focus();
        return false;
        }
     return true;      
     }
  function isBlank(s) {
     return (s == "");
     }
  </SCRIPT>

  <BODY onLoad="document.userInfos.username.focus();">
  <H1><CENTER>Identification </H1></CENTER>
  <CENTER><TABLE BORDER=1>
  <FORM  NAME=userInfos>
  <TR><TD>User: </TD><TD>
  <INPUT TYPE="text" NAME=username LENGTH=20></TD></TR>
  <TR><TD>Password: </TD><TD> 
  <INPUT TYPE="password" NAME=password LENGTH=20>
  </TD></TR>
  <TR ALIGN=center>
  <TD></TD><TD>
  <INPUT TYPE="button" VALUE="Ok" onClick="login()">
  </TD></TR></TABLE></FORM></CENTER></BODY></HTML>
  

Posted On: 10-Jul-1999

internet.commerce