<html>
<head>
<title>Remember Me</title>
<script type="text/javascript" src="remember.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form method="post" onSubmit="return checkLogin();" method="post" autocomplete="off" name="login" >
<table>
<tr>
<td colspan="2">
<div class="login_error" id="login_error"></div>
</td>
</tr>
<tr>
<td>
Username :
</td>
<td>
<input type="text" id="username" value="" name="username"/>
</td>
</tr>
<tr>
<td>
Password :
</td>
<td>
<input type="password" id="password" value="" name="password"/>
</td>
</tr>
<tr>
<td>
<input type="checkbox" value="1" name="remember_me" id="remember_me"/>Remember me
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" id="submit" value="Login">
</td>
</tr>
</table>
</form>
<script type="text/javascript" language="javascript">
var username=readCookie("username");
var password=readCookie("password");
if (readCookie("username")!="" && readCookie("username")=="undefined" && readCookie("username")!="" && readCookie("username")=="undefined")
{
eraseCookie("username");
eraseCookie("password");
document.getElementById ('username').value = ''; // Change the names of the fields at right to match the ones in your form.
document.getElementById ('password').value = '';
document.getElementById('remember_me').checked = false;
}
else{
if (username!=null && username!="" && password!=null && password!="")
{
document.getElementById('remember_me').checked = true;
document.getElementById ('username').value = readCookie("username"); // Change the names of the fields at right to match the ones in your form.
document.getElementById ('password').value = readCookie("password");
}
}
</script>
</body>
</html>
remember.js
function checkLogin(){
var name=document.getElementById('username').value;
document.getElementById('login_error').innerHTML ='';
if(name == ''){
document.getElementById('login_error').innerHTML = 'Please Enter User Name';
return false;
}
else if(document.getElementById('password').value == ''){
document.getElementById('login_error').innerHTML = 'Please Enter Passoword';
return false;
}
else {
remember();
}
}
function remember(){
if(document.getElementById('remember_me').checked == true){
toMem();
}else{
eraseCookie();
}
}
function newCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}
function readCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name)
{
return unescape(y);
}
}
}
function checkCookie()
{
var username=getCookie("username");
if (username!=null && username!="")
{
alert("Welcome again " + username);
}
else
{
username=prompt("Please enter your name:","");
if (username!=null && username!="")
{
setCookie("username",username,365);
}
}
}
function eraseCookie(name) {
newCookie(name,"",1);
newCookie('username',"",1);
newCookie('password',"",1);
}
function toMem() {
var user = document.getElementById ('username').value;
var pwd = document.getElementById ('password').value
newCookie('username', user,'1'); // add a new cookie as shown at left for every
newCookie('password', pwd,'1'); // field you wish to have the script remember
}
function delMem() {
eraseCookie('username'); // make sure to add the eraseCookie function for every field
eraseCookie('password');
document.login.username.value = ''; // add a line for every field
document.login.password.value = '';
}
Post a Comment
Post a Comment