Home > Blockchain >  is there a way to make a password in HTML
is there a way to make a password in HTML

Time:11-16

I am new to coding so I tried looking up how to make a password in HTML. But I ended up getting more confused and nothing that I had tried from anywhere worked or I just didn't understand it. I want to make a password that if correct will reveal a large amount of text and I have no idea what to do to create said password, so could you help me?

CodePudding user response:

The OP asked for some code so I'll provide a simple demo. Keep in mind to never do something like this in production code! The password will be visible for everybody!

// this is the correct password
var password = "12345";

var submitButton = document.getElementById("submit"); 
var passwordField = document.getElementById("password"); 
var hiddenText = document.getElementById("text"); 

// when submit is clicked ...
submitButton.addEventListener("click", function() {
  // ... get the entered password ...
  var enteredPassword = passwordField.value;
  // ... and compare with the real password
  if (enteredPassword === password) {
    // if both passwords match then show the hidden text
    hiddenText.style.display = "block";
  }
});
<input id="password" type="password">
<button id="submit" type="button">Submit</button>

<p id="text" style="display: none;">This is the hidden text!!!</p>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

CodePudding user response:

If you want that the user will write some password, you need js. In html add label : password & input type=“text”, and button to send the password. Then use js to make if statements ..

  1. catch the value of the password input 2.catch the button with variable and add it addEventListener(click,function(){
  2. write if statement like: if(password.length==4){ alert(invalid password) });
  •  Tags:  
  • html
  • Related