简体   繁体   English

如何让我的密码提示只在我打开我的网站时出现一次,而不是每次我重新加载页面或重新访问它时出现

[英]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.

相关问题 打开控制台时如何不重新加载页面? - How to not reload my page when I open up my console? 如何让网页只显示一次? - How do I make a web page show up only once? 如何使弹出窗口仅对页面上的新访问者加载一次? - How do I get my pop up to only load once for new visitors on my page? 如何让我的 cookie 同意横幅为每个用户(ip)弹出一次 - How do I make it so that my cookie consent banner pops up once for every user(ip) 每次用户被定向到视图/页面时,如何让我的 Javascript 不弹出 - How can I make my Javascript not pop up every time a user gets directed to the a View/Page 如何使我的所有图形显示在html页面上? - How do I make all my graphs show up on my html page? 单击图片时,如何使文字显示在图片旁边? - How do I make text show up next to my picture when I click on it? 如何使我的页面可以关闭或重新加载,但当我再次打开页面时内容不会消失? - How do I make it so my page can close or reload but the content wont disappear when i open the page again? UI提示反复在电子表格中弹出,如何使其仅弹出一次? - UI Prompt repeatedly popping up in spreadsheet, how can I make it pop up only once? 打开页面时出现通知错误 - I get a notice error when I open up my page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM