簡體   English   中英

如何強制用戶在訪問網頁前輸入密碼?

[英]How to force the user to write a password before accessing a webpage?

我正在從事一個 Web 開發項目,我被要求強制用戶在授予他們訪問主網頁的訪問權限之前填寫主頁表單中的密碼字段。 但是,即使我將“必需”標簽放在密碼輸入字段中,我也會得到相反的行為。 當沒有寫入密碼時,該網頁會向用戶提供訪問權限,而在寫入密碼時,則不會。 如果有人可以幫助解決這個問題,那將非常有幫助。 我將在這里留下輸入表單的代碼以及應該提供這種行為的函數。

----表單的HTML代碼(關注第二個輸入,id="form-psw"----

<div id="homepage-form">
  <form id="homepage-data-form" class="form-container">
    <h1 id="homepage-form-heading">Login</h1>

    <label for="email" class="form-label bold">Email</label>
    <input id="form-email" type="text" placeholder="Enter Email" name="email" required>

    <label for="psw" class="bold">Password</label>
    <input id="form-psw" type="password" placeholder="Enter Password" name="psw" required>
  </form>
</div>

-----控制解釋行為的JS代碼------

function checkCookie() {
  var cname = document.getElementById("form-email").value;
  var user = getCookie(cname);
  if (user == "") {
    alert("Sorry, the provided email is not registered. Click on the Register option to get your account.");
  } else {
    window.location.href = "main.html";
  }
}

讓網頁受密碼保護從來都不是一個聰明的主意。 這是因為漏洞太多。 做這樣的事情最好的方法是使用 .htaccess 文件。 順便說一句,輸入字段的 required 屬性僅在您將其放入表單標記中時才有效

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM