مشاهدة النسخة كاملة : Password and Login script
bahattab
22-09-2009, 05:41 PM
Login and Password script
Credit: Donated By supernut@webtv.net
Description:
A simple login and password script. Login is JavaScript, password is Kit. To change this information, simply go into the script and change it. Be sure to also change the target page.
Example:
Login Area
UserID: ---------
Password:---------
Directions: Simply insert this in the <body> section:
<script language="javascript">
<!--//
/*This Script allows people to enter by using a form that asks for a
UserID and Password*/
function pasuser(form) {
if (form.id.value=="JavaScript") {
if (form.pass.value=="Kit") {
location="page2.html"
} else {
alert("Invalid Password")
}
} else { alert("Invalid UserID")
}
}
//-->
</script>
<center>
<table bgcolor="white" cellpadding="12" border="1">
<tr><td colspan="2"><center><h1><i><b>Login
Area</b></i></h1></center></td></tr>
<tr><td><h1><i><b>UserID:</b></i></h1></td><td><form name="login"><input
name="id" type="text"></td></tr>
<tr><td><h1><i><b>Password:</b></i></h1></td><td><input name="pass"
type="password"></td></tr>
<tr><td><center><input type="button" value="Login"
onClick="pasuser(this.form)"></center></td><td><center><br><input
type="Reset"></form></td></tr></table></center>
http://www.javascriptkit.com/script/cut76.shtml
bahattab
22-09-2009, 05:49 PM
Keeper Password Protect
Credit: Joe Barta (jbarta@apk.net) (Professional Web Design) (http://junior.apk.net/%7Ejbarta/)
Description:
The below script provide every extensive password protecting for a page. This is perhaps one of the best JavaScript password protector out there. Uses JavaScript.
Example: password: "page2"
Directions
Step 1:
Save this image onto your harddrive:
http://www.atyafonline.com/vb/imgcache/3712.png
Step 2:
Copy the below into the <body> tags of the starting page (The page before the password protected one).
<SCRIPT LANGUAGE="javascript">
<!--- Hide from tired old browsers
var nifty_little_window = null;
function gateKeeper() {
nifty_little_window = window.open('gatekeep.html', 'theKeeper',
'width=350,height=200,resizable=1');
}
// End hiding --->
</SCRIPT>
<form>
<input type="button" value="Enter Here" onClick="gateKeeper()"
</form>
Step 3:
Copy this and save it as a new page. Save it as "gatekeep.html"
<HTML>
<HEAD>
<TITLE>Gate Keeper</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--- Hide from tired old browsers that should be put to pasture.
////////////////////////////////////////////////////////////////////
/// Get your very own Gate Keeper from Professional Web Design ///
/// http://junior.apk.net/~jbarta/weblinks/gate_keeper/ ///
////////////////////////////////////////////////////////////////////
function goForit() {
var location;
var password;
password=this.document.testform.inputbox.value
location=password + ".html"
fetch(location)
theKeeper=window.close()
}
function fetch(location) {
var root;
if (opener.closed) {
root=window.open('','theKeepersGopher','toolbar=ye s,location=yes,status=yes,menubar=yes,scrollbars=y es,resizable=yes,copyhistory=no');
root.location.href = location;
} else {
opener.location.href = location;
}
}
// End hiding --->
</SCRIPT>
</HEAD>
<BODY BACKGROUND="keeper.gif">
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR>
<TD ROWSPAN=2 WIDTH=50%>
<TD WIDTH=50% ALIGN=CENTER VALIGN=MIDDLE>
<FONT FACE="ARIAL" SIZE=2><B>Hold on there buddy. You'll need a password to get in here. We're tryin' to keep out the riff-raff.</B></FONT><BR>
<TR>
<TD WIDTH=50% ALIGN=CENTER VALIGN=BOTTOM>
<CENTER>
<FORM NAME="testform">
<INPUT TYPE="text" NAME="inputbox" VALUE="" size=20>
<INPUT TYPE="button" NAME="button" Value="Submit Password" onClick="goForit(this.form)">
<!--- You can remove the following link if you want.
I just added it to satisfy my own selfish interests.
Just remove the following line and this comment. --->
<P><FONT SIZE=1 FACE="COMIC SANS MS"><A HREF="http://junior.apk.net/~jbarta/weblinks/gate_keeper/" TARGET="_blank"><B>Gate Keeper</B></A></FONT>
</FORM>
</CENTER>
</TABLE>
</BODY>
</HTML>
Step 4 (final one):
You're basically done. The above will password protect any page, the password being the name of the file. For example, say I want to protect mypage.htm. The password would be "mypage". So all you have to do now is rename the page you want to protect to a longer and more complicated file name, and that will be the password that will access that page. No, you don't have to add anything to the protected page.
Note: It seems this script can only protect pages that end in ".html", and NOT ".htm", so be sure to rename the extensions too.
Please realize again that this script is written by Joe Barta, a talented webmaster.
bahattab
22-09-2009, 05:56 PM
Login and password script II
Credit: Anubhav Misra (http://www.teenz2k.com/)
Description:
This is a variation of the original Login and Password script (http://javascriptkit.com/script/cut76.shtml) that will take users to two different pages, depending on whether the entered combination is correct or not.
Example:
(in demo, user="free", password="javascript")
ENTER USER NAME :
ENTER PASSWORD :
Directions:
Simply insert the below into the <body> section of the login page:
<form>
<p>ENTER
USER NAME : <input type="text" name="text2">
</p>
<p> ENTER PASSWORD :
<input type="password" name="text1"> <input type="button"
value="Check In" name="Submit"
onclick=javascript:validate(text2.value,"free",text1.value,"javascript")
>
</p>
</form>
<script language = "javascript">
/*
Script by Anubhav Misra (anubhav_misra@hotmail.com)
Submitted to JavaScript Kit (http://javascriptkit.com)
For this and 400+ free scripts, visit http://javascriptkit.com
*/
function validate(text1,text2,text3,text4)
{ if (text1==text2 && text3==text4) load('success.htm'); else {
load('failure.htm'); }
}
function load(url)
{ location.href=url;
}
</script>
<p align="center"><font face="arial" size="-2">This free
script provided by <a href="http://javascriptkit.com">JavaScript
Kit</a></font></p>
Configuring the script
To change the login/password, change "free" and "javascript" inside the script, respectively. To change the destination URLs, modify "success.html" and "failure.html."
bahattab
22-09-2009, 05:59 PM
Password Protect a page
Credit: Not indicated
Description:
The below script will provide low level password protection to a page.
Example:
(Enter "letmein" as password)
Directions:
Simply cut and paste the following into the <body> tags of your page. To configure the password, change letmein. To change the password protected page (the target page), change protectpage.html.
<SCRIPT>
function passWord() {
var testV = 1;
var pass1 = prompt('Please Enter Your Password',' ');
while (testV < 3) {
if (!pass1)
history.go(-1);
if (pass1.toLowerCase() == "letmein") {
alert('You Got it Right!');
window.open('protectpage.html');
break;
}
testV+=1;
var pass1 =
prompt('Access Denied - Password Incorrect, Please Try Again.','Password');
}
if (pass1.toLowerCase()!="password" & testV ==3)
history.go(-1);
return " ";
}
</SCRIPT>
<CENTER>
<FORM>
<input type="button" value="Enter Protected Area" onClick="passWord()">
</FORM>
</CENTER>
bahattab
22-09-2009, 06:01 PM
Random Password Generator
Credit: JavaScript Kit (http://www.javascriptkit.com/)
Description:
Having a difficult time thinking up a password? Need to automatically generate a password as part of a larger application? This script can help! It randomly creates a password of any specified length using alphabetic and numeric input.
Example:
Password Length:
Directions:
Simply insert the below into the <body> section of your page:
<script>
//Random password generator- by javascriptkit.com
//Visit JavaScript Kit (http://javascriptkit.com) for script
//Credit must stay intact for use
var keylist="abcdefghijklmnopqrstuvwxyz123456789"
var temp=''
function generatepass(plength){
temp=''
for (i=0;i<plength;i++)
temp+=keylist.charAt(Math.floor(Math.random()*keyl ist.length))
return temp
}
function populateform(enterlength){
document.pgenerate.output.value=generatepass(enter length)
}
</script>
<form name="pgenerate">
<input type="text" size=18 name="output">
<input type="button" value="Generate Password" onClick="populateform(this.form.thelength.value)"><br />
<b>Password Length:</b> <input type="text" name="thelength" size=3 value="7">
</form>
<p align="center">This free script provided by<br />
<a href="http://javascriptkit.com">JavaScript
Kit</a></p>
bahattab
22-09-2009, 06:05 PM
Password protection by .htaccess
Ever wanted a specific directory in your site to be available only to people who you want it to be available to? Ever got frustrated with the seeming holes in client-side options for this that allowed virtually anyone with enough skill to mess around in your source to get in? htaccess is the answer!
There are numerous methods to password protecting areas of your site, some server language based (such as ASP, PHP or PERL) and client side based, such as JavaScript. JavaScript is not as secure or foolproof as a server-side option, a server side challenge/response is always more secure than a client dependant challenge/response.
htaccess is about as secure as you can or need to get in everyday life, though there are ways above and beyond even that of htaccess. If you aren't comfortable enough with htaccess, you can password protect your pages any number of ways, and JavaScript Kit has plenty of password protection (http://www.javascriptkit.com/script/cutindex6.shtml) scripts for your use.
The first thing you will need to do is create a file called .htpasswd. I know, you might have problems with the naming convention, but it is the same idea behind naming the htaccess file itself, and you should be able to do that by this point. In the htpasswd file, you place the username and password (which is encrypted) for those whom you want to have access.
For example, a username and password of wsabstract (and I do not recommend having the username being the same as the password), the htpasswd file would look like this:
wsabstract:y4E7Ep8e7EYV Notice that it is UserName first, followed by the Password. There is a handy-dandy tool (http://www.tools.dynamicdrive.com/password/) available for you to easily encrypt the password into the proper encoding for use in the httpasswd file.
For security, you should not upload the htpasswd file to a directory that is web accessible (yoursite.com/.htpasswd), it should be placed above your www root directory. You'll be specifying the location to it later on, so be sure you know where you put it. Also, this file, as with htaccess, should be uploaded as ASCII and not BINARY.
Create a new htaccess file and place the following code in it:
AuthUserFile /usr/local/you/safedir/.htpasswd
AuthGroupFile /dev/null
AuthName EnterPassword
AuthType Basic
require user wsabstract
</blockquote>The first line is the full server path to your htpasswd file. If you have installed scripts on your server, you should be familiar with this. Please note that this is not a URL, this is a server path. Also note that if you place this htaccess file in your root directory, it will password protect your entire site, which probably isn't your exact goal.
The second to last line require user is where you enter the username of those who you want to have access to that portion of your site. Note that using this will allow only that specific user to be able to access that directory.
This applies if you had an htpasswd file that had multiple users setup in it and you wanted each one to have access to an individual directory. If you wanted the entire list of users to have access to that directory, you would replace Require user xxx with require valid-user.
The AuthName is the name of the area you want to access. It could anything, such as "EnterPassword". You can change the name of this 'realm' to whatever you want, within reason.
We are using AuthType Basic because we are using basic HTTP authentication.
http://www.javascriptkit.com/howto/htaccess3.shtml