Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm creating a password generator of n length. The user deciedes the length by inputting a number. I'm having trouble with how to validate that

I'm creating a password generator of n length. The user deciedes the length by inputting a number. I'm having trouble with how to validate that 'num' is between the values of 6-25 also If the number entered by the user is valid, I want to use a for loop that iterates that number of times. In each iteration of the loop, randomly select one of the characters from the chars string and concatenate it to the password variable.

Here is my HTML

pgen

Generate a Strong Password

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 between 0 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()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Managing Your Information How To Design And Create A Textual Database On Your Microcomputer

Authors: Tenopir, Carol, Lundeen, Gerald

1st Edition

1555700233, 9781555700232

More Books

Students also viewed these Databases questions

Question

Understand the importance of organizational change.

Answered: 1 week ago

Question

7. Discuss the key features of the learning organization.

Answered: 1 week ago