(Solved) : M Creating Password Generator N Length User Deciedes Length Inputting Number M Trouble Val Q28594637 . . .
I’m creating a password generator of n length. The user deciedesthe length by inputting a number. I’m having trouble with how tovalidate that ‘num’ is between the values of 6-25 also If thenumber entered by the user is valid, I want to use a for loop thatiterates that number of times. In each iteration of the loop,randomly select one of the characters from the chars string andconcatenate it to the password variable.
Here is my HTML
<!DOCTYPE html>
<html>
<head>
<meta charset=”UTF-8″>
<title>pgen</title>
<link rel=”stylesheet” href=”password.css”>
<scriptsrc=”https://code.jquery.com/jquery-3.1.1.min.js”></script>
</head>
<body>
<h1>Generate a Strong Password</h1>
<label for=”num”>Number of characters:</label>
<input type=”text” id=”num”><br>
<label for=”password”>Password:</label>
<input type=”text” id=”password” disabled><br>
<label> </label>
<input type=”button” id=”generate” value=”GetPassword”>
<input type=”button” id=”clear”value=”Clear”><br>
<script src=”password.js”></script>
</body>
</html>
JAVASCRIPT/ JQUERY
“use strict”;
$(document).ready(function() {
var getRandomNumber = function(max) {
var random;
if (!isNaN(max)) {
random = Math.random(); //value >= 0.0 and < 1.0
random = Math.floor(random * max); //value is an integer between0 and max – 1
random = random + 1; //value is an integer between 1 and max
}
return random;
};
$(“#generate”).click(function() {
var isValid = true;
var num = $(“#num”).val().trim();
//HELP
if(num.length < 6 & num.length > 25){
$(“#num”).next().text(“Please enter a valid number 6 – 25”);
isValid = false;
}else{
$(“#num”).next().text(“”);
}
$(“#num”).val(num);
if(isValid == “true”){
for(var i = 1; i <= num; i ++){
r = getRandomNumber().random;
}
$(“#password”).val(r);
}
//HELP
$(“#password”).val( “” ); // clear previous entry
var chars =”0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-+!@”;
}); // end click()
$(“#clear”).click(function() {
$(“#num”).val( “” );
$(“#password”).val( “” );
$(“#num”).focus();
}); // end click()
// set focus on initial load
$(“#num”).focus();
}); // end ready()
Expert Answer
Answer to M Creating Password Generator N Length User Deciedes Length Inputting Number M Trouble Val Q28594637 . . .
OR