JAVASCRIPT: Need help with this assignment - Please give scrreen shots showing i
ID: 3918069 • Letter: J
Question
JAVASCRIPT: Need help with this assignment - Please give scrreen shots showing indentation for working coding and the code to copy and work with. Thank you -
You will be developing two scripts. Coding techniques will involve input, output, section and iteration. You will need to use variables and functions, but nothing more complex than was taught through the first 4 weeks of class.
Assessment of your productions will include the following dimensions:
Does the code meet functional requirements?
Does the code work when tested in a browser?
Is the code well organized and readable?
Does the code make effective use of comments and naming conventions?
Assignment #2: Password Generator
Traditional SQL requires the DBA (database administrator) to supply user passwords. Your DBA has asked you to write some code to help generate secure passwords to use.
Ask the user how many passwords they wish to generate. Validate that the response is numeric and not negative. Then ask the user how long each password should be. Validate that the response is numeric and in the range 8 to 16 (inclusive). Then generate the list of passwords, writing it to the document under an attractive heading.
Password rules:
For 85% credit: passwords can contain: upper-case English letters
For 95% credit: passwords can contain: upper-case English letters, lower-case English letters, numbers, and special characters ! through / (but no other special characters).
For 100% credit: each password character should be selected from one of the categories shown in the 95% credit list above; but you are not responsible for ensuring that every password contains at least one character from eachcategory. To prevent super hard passwords, though, it should be twice as likely that letters are selected, i.e., a 33% chance of choosing the upper-case category, a 33% chance of choosing the lower-case category, a 16% chance of choosing a number, and a 16% chance of choosing a special character.
Notes and Hints
An ASCII table of characters and their decimal numeric equivalents will be very useful here. One reference: https://en.wikipedia.org/wiki/ASCII (Links to an external site.)Links to an external site..
You'll need to use the String.fromCharCode() function; it takes an ASCII code and turns it into a character, e.g., String.fromCharCode(65) returns "A".
To make output easier to read, write the passwords within a preformatted block, starting with <pre> and ending with </pre>.
Sample Output
Sample output is shown below, for 10 passwords of 12 characters in length, in the 100% credit case.
Passwords
Project Workflow Recommendations
Start with asking the two questions requested, how many passwords and how long each should be.
Then, as a placeholder, generate passwords that are filled with a specific character, like an "X". The result should look right except they are all the same and are obviously poor passwords (grin).
Then, in place of the "X", generate a random number between 65 and 90 (think a little; it's a simple math issue to change range we usually use, say 1 to 10, to something in the range of 1 to 26 (letters in the alphabet), then add to get that into the range you want). Use the function I gave you to turn that into a letter. Add THAT to the string in place of the "X". Now your passwords should be full of random capital letters.
Figure out how to generate all the ranges necessary: for special characters, 33 to 47; for numbers, 48 to 57; for lower-case letters 97 to 122.
From that point, all you need to do is generate a random number from 1 to 4, using that to decide whether to generate a special character, number, upper-case letter, or lower-case letter.
The very last thing to do is figure out how to make the selection smarter. Instead of selecting the categories with equal probability, see if you can do what's mentioned in the problem about the likelihood of selecting a particular category.
If you can't get it all working, turn in a working version that does the most that you can. If you have non-working code, comment it out and tell me what you were trying to do there; that may be worth some credit.
Explanation / Answer
here is your code : ---------->>>>>>>>
<!DOCTYPE html>
<html>
<head>
<title>Password Generator</title>
</head>
<script type="text/javascript">
function validate_Hmany(){
var a = document.getElementById("Hmany").value;
if(isNaN(a)){
document.getElementById("error").innerHTML = "How Many is Not A Number";
document.getElementById("Hmany").value = "";
return false;
}else{
document.getElementById("error").innerHTML = " ";
return true;
}
}
function validate_Hlong(){
var a = document.getElementById("Hlong").value;
if(isNaN(a)){
document.getElementById("error").innerHTML = "How Long is Not A Number";
document.getElementById("Hmany").value = "";
return false;
}else{
var b = parseInt(a);
if(b < 8 || b > 16){
document.getElementById("error").innerHTML = "How Long is Not in Range";
document.getElementById("Hmany").value = "";
return false;
}else{
document.getElementById("error").innerHTML = " ";
return true;
}
}
}
function randomXToY(minVal,maxVal,floatVal){
var randVal = minVal+(Math.random()*(maxVal-minVal));
return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal);
}
function generateChar(){
var n = parseInt(Math.floor((Math.random() * 100) + 1));
if(n <= 16){
var ch = randomXToY(48,57,'undefined');
return String.fromCharCode(parseInt(ch));
}else if(n <= (16+33)){
var ch = randomXToY(97,122,'undefined');
return String.fromCharCode(parseInt(ch));
}else if(n <= (16+33+33)){
var ch = randomXToY(65,90,'undefined');
return String.fromCharCode(parseInt(ch));
}else{
var ch = randomXToY(33,47,'undefined');
return String.fromCharCode(parseInt(ch));
}
}
function generate_pass(){
if(validate_Hmany() && validate_Hlong()){
var str = "";
var n = document.getElementById("Hmany").value;
var n1 = document.getElementById("Hlong").value;
for(var i = 0;i<n;i = i + 1){
str = str + "<pre>";
for(var j = 0;j<n1;j++){
str = str+generateChar();
}
str = str + "</pre>";
}
document.getElementById("res").innerHTML += str;
}
}
</script>
<style type="text/css">
.Form{
width: 500px;
height: 200px;
border-radius: 10px;
margin: 0 auto;
background-color:#CDFF65;
padding-top: 30px;
}
.result{
width:400px;
min-height:300px;
margin: 0 auto;
border-radius: 10px;
background-color: silver;
}
.result > pre{
color:red;
font-size: 24px;
}
</style>
<body>
<h1 id="error"> </h1>
<div class="Form">
<form>
<p>
<span>Enter How Many Password :- </span>
<input type="text" id="Hmany" value="">
</p>
<p>
<span>Enter How Long Each Password :- </span>
<input type="text" id="Hlong" value="">
</p>
<br>
<p>
<input type="button" name="" value="Get">
</p>
</form>
</div>
<div class="result" id="res">
<h1>Password Generated Result</h1>
</div>
</body>
</html>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.