如何在仅应使用JS加密的代码中设置密码

时间:2019-07-15 18:34:45

标签: javascript json security web-storage

我是一个输入用户名和密码的小型应用程序,我使用json和js来检索用户名和密码,然后通过网络存储将它们存储起来,如果用户== mohamed + password = 123456,则登录成功我需要一种方法只能使用js来使密码不写在代码中,也不是用加密的代码编写,而只能用js

我不知道怎么做,因为我是初学者

<!DOCTYPE html>
<html>
<body>

<h2>Store and retrieve data from local storage.</h2>
<input type="text" value="" id="demo1">

<input type="password" value="" id="demo2">


<p>UserName: mohamed, password: 123456, this not a javascript
 handling this is JSON and LocalStorage Which can be done online without 
 Server</p>
<p id="demo"></p>
<button type="button" onclick="submit()">Submit</button>
<script>
function submit() {

var user1, myJSON, text, mohamed;

user1 = {};
var x = document.getElementById("demo1").value;
var y = document.getElementById("demo2").value;
user1.userName = x;
user1.password = y;
myJSON = JSON.stringify(user1);
localStorage.setItem("account1", myJSON);

text = localStorage.getItem("account1");
mohamed = JSON.parse(text);

                           // problem here password appeared in the code
if (mohamed.userName == "mohamed" && mohamed.password == "123456") {
    document.getElementById("demo").innerHTML = "Welcome to Your Account";
} else {
document.getElementById("demo").innerHTML = "password or userName is not 
correct";
}
}
</script>

</body>
</html>

将此mohamed.password ==“ 123456”更改为*****或其他类似内容,请仅使用JS告诉我

0 个答案:

没有答案