簡體   English   中英

HTML登錄頁在頁面源中顯示憑據

[英]HTML Login Page shows creds in page source

好吧,所以我想為一個我的朋友們建立一個私人網站,讓其他人無法訪問或注冊。我的腳本是...

<html>
<head>
<title>
Login page
</title>
</head>
<body>
<h1 style="font-family:Comic Sans Ms;text-align="center";font-size:20pt;
color:#00FF00;>
Simple Login Page
</h1>
<form name="login">
Username<input type="text" name="userid"/>
Password<input type="password" name="pswrd"/>
<input type="button" onclick="check(this.form)" value="Login"/>
<input type="reset" value="Cancel"/>
</form>
<script language="javascript">
function check(form)/*function to check userid & password*/
{
 /*the following code checkes whether the entered userid and password are matching*/
 if(form.userid.value == "myuserid" && form.pswrd.value == "mypswrd")
  {
    window.open('target.html')/*opens the target page while Id & password matches*/
  }
 else
 {
   alert("Error Password or Username")/*displays error message*/
  }
}
</script>
</body>
</html>

使用該代碼,某人可以打開頁面源代碼,並查看憑據。 有什么方法可以隱藏和加密它,甚至可以添加一些其他帳戶?

您永遠不要在客戶端代碼中放置敏感信息,因為查看頁面源代碼或檢查元素的任何人都可以看到敏感信息。 您應該在客戶端驗證的唯一內容是必填字段或有效的電子郵件等內容。 然后,在服務器端腳本中執行敏感驗證,就像上面所做的一樣。 我還必須指出,使用if語句檢查用戶是非常糟糕的做法。 您應該更多地處理應用程序的服務器端邏輯。

您用客戶端JavaScript編寫的任何內容都有可能在其瀏覽器中被其他人看到,因此,應在服務器上處理諸如身份驗證之類的事情。

同樣重要的是要知道您切勿以純文本形式存儲密碼。

通過閱讀代碼,我可以看到的另一件重要的事情是,我可能只是導航至https://whatever.com/target.html並查看您要使用密碼保護的頁面。

如果您有興趣使用這種功能構建網站,則需要使用服務器端語言並為服務器編寫一些代碼。

執行服務器端身份驗證的最簡單方法是使用.htaccess和.htpasswd文件進行基本的HTTP身份驗證。

暫無
暫無

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

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