javascript| Tutorial
Use JavaScript for password protection
With the rapid development of the Internet, the earth has become smaller, people can cross the boundaries of time and space to communicate in cooperation. But then there are some vandalism hackers, which makes it possible for program designers to think about hacking in their applications, so it's natural to think of protection. This tutorial will teach you how to use JavaScript for password protection. There are several ways to use JavaScript to password protect a Web page. One of the earliest methods is to be tolerant of the user without knowing the target filename, as follows:
<script language= "JavaScript" ><!--
function Go () {
Window.location.href = "http://www.somewhere.com/" +
Document.formName.passwordName.value + '. html ';
return false;
}
file://--></ Script>
The way to use this JavaScript script in a Web page is:
<form name= "FormName" >
Enter Password: <input type= "Password" name= "Passwordname"
Value= "" size=8>
</FORM>
One disadvantage of using this JavaScript script is that users can check the source code and discover the location of the file directory. To find better security, you should protect your file directory by placing a default file (index.html) into JavaScript scripts so that your server always sends a message when the directory is requested. If you do not include a default file in your file directory, the Web server sends all the files contained in your directory, which is the hidden danger of insecurity.
The point here is that using JavaScript to password-protect a file is not a very safe way to do this. To achieve a higher safety factor, CGI or server functions are recommended here, such as. htaccess.