[英]How do I make my password prompt only show up once when I open up my website instead of every time I reload the page or revisit it
Can I set a time limit (for example in 8 hours you have to retype the password)?我可以设置时间限制吗(例如 8 小时后您必须重新输入密码)? Here's my very simple javascript:
这是我的非常简单的 javascript:
<SCRIPT language="JavaScript">
<!--hide
var password;
var pass1="x10Kz4iz4ZvEB2wgUBA5otc1";
var pass2="x10Kz4iz4ZvEB2wgUBA5otc1";
var pass3="x10Kz4iz4ZvEB2wgUBA5otc1"
password=prompt('Please enter your password to view this page!',' ');
if (password==pass1 || password==pass2 || password==pass3)
alert('Password Correct! Click OK to enter!');
else
{
alert('Uh oh try again');
window.location="#";
}
//-->
</SCRIPT>
I have this under the head tag of my HTML text.我在 HTML 文本的标题标签下有这个。 Thank you:)
谢谢:)
This is not really a secure way of protecting your website because anyone can look at the source code of a page and see the Javascript along with the passwords you wrote there.这并不是真正保护您网站的安全方法,因为任何人都可以查看页面的源代码并看到 Javascript 以及您在其中编写的密码。
However, for learning purposes, you might want to learn about setting and getting cookies ( How do I create and read a value from cookie? ).但是,出于学习目的,您可能想了解如何设置和获取 cookies( 如何从 cookie 中创建和读取值? )。 You can store the time the user logged in, and next time check if it has been eight hours (just compare the time and date of last login to current login time and date).
您可以存储用户登录的时间,下次检查是否已经八小时(只需将上次登录的时间和日期与当前登录时间和日期进行比较)。
Also, to get the current time, you should read up on the Javascript Date() function.此外,要获取当前时间,您应该阅读 Javascript Date() function。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.