0

I'm small app with inputs user and password , i used json and js to retrieve the username and password then store them via web storage finaily , if the user == mohamed + password = 123456 , login successful i need a way in only js to make the password not be written in the code or written in code encrypted but with js only

i have no idea how to do something like that as i'm beginner

<!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>

changing this mohamed.password == "123456" to be something ***** or anything else like please give me idea with JS only

Debug Diva
  • 26,058
  • 13
  • 70
  • 123
Mahmoud Magdy
  • 662
  • 10
  • 13
  • 5
    It is impossible, that is why we have serverside to do it correctly. – epascarello Jul 15 '19 at 18:37
  • 3
    You can certainly do it in JS only... but some of that JS will have to be on the server side, like with NodeJS :) – IceMetalPunk Jul 15 '19 at 18:38
  • Just to put a fine point on it. There's no such thing as hidden client-side JavaScript code. It doesn't exist. You can obfuscate to your heart's content but that's really it. – zfrisch Jul 15 '19 at 18:48

0 Answers0