Question

In: Computer Science

Using JavaScript You must submit a file called, called pass.js pass.js: Validator of passwords Your task...

Using JavaScript

You must submit a file called, called pass.js


pass.js: Validator of passwords

Your task this week will be to program a valid password validator.

A password is safe only if it satisfies the following constraints:

- It has from 5 to 10 characters (inclusive)
- It contains at least one lowercase letter, at least one capital letter and at least one number
- The first character is different from the last

Once the password is entered and validated, the user is asked to copy it again to validate.

Course of the program

More precisely :

1. Ask the user to enter a password with:

      prompt ("Please choose a password");

2. Check if the password matches the requirements

   2a. If the password is invalid, display "Invalid password" and end the program (the rest of the program runs only if this step was done correctly)

   2b. If the password is correct, go to step 3

3. Ask the user to enter the password again with:

      prompt ("Please enter the password a second time to confirm");

4. Check if both passwords are the same

   4a. If the passwords do not match, show "You did not enter the same password twice" and ask to start again
   4b. If the two entered passwords match, go to step 5

5. Once the password is valid and entered twice correctly, display "Password saved!"

Here is an example of the execution of the program :

Please choose a password
> the user enters "abc"
Invalid password

Another example :


Please choose a password
> the user enters "l33th4xx0r"
Please enter the password a second time to confirm
> the user enters "abc"
You have not entered the same password twice
Please enter the password a second time to confirm

> the user enters "l33th4xx0r"
Password saved!

Your program must be complete, with comments that
indicate the name of the file, the author (your name), a brief
description of the usefulness of the program. There must also be
comments that explain what each variable corresponds to,
and the operation of the program. Use statements of
appropriate loop, correct indentation, and block statements
in the body of if and loops. Your program should avoid
redundant and repetitive calculations.

Solutions

Expert Solution

/*
Filename : pass.js
Author : (Your Name)
This program validates password against,
- It has from 5 to 10 characters (inclusive).
- It contains at least one lowercase letter, at least one capital letter and at least one number.
- The first character is different from the last.

*/

// variable to take input password from user
var passsword= prompt("Please choose a password");
// Regular expression to check wheather the password has 1 digit,1 uppercase character, 1 lowercase character and
//having 5-10 character length both inclusive.
var regex = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{5,10}$/;
//Condition to check the regular expression and first and last digit of password is different
if (passsword.match(regex) && passsword.charAt(0) != passsword.charAt(passsword.length-1)){
   var confirmpass = prompt ("Please enter the password a second time to confirm");
   //If both entry for password is equal
   if(passsword == confirmpass){
       alert("Password saved!");
   }else{
       alert("You did not enter the same password twice");
   }          
}else{
   alert("Invalid password");
}


Related Solutions

Using JavaScript You must submit a file, called indentation.js indentation.js: program to indent The following program...
Using JavaScript You must submit a file, called indentation.js indentation.js: program to indent The following program is difficult to follow because of its indentation: print ( "binary"); var n = Math.pow (2, 31) - 1; var bits = 0; while (n> 0) { bits + = n & 1; n >> = 1; } print ("Number of bits at 1:" + bits); for (var i = 1; i <= bits; i ++) { var str = ""; if (i% 3...
using C thank you Must submit as MS Word file with a screenshot of the 3...
using C thank you Must submit as MS Word file with a screenshot of the 3 outputs. Run your program 3 times. the output must be in a screenshot not typed for the each time you run the program. thank you Modify the code below to implement the program that will sum up 1000 numbers using 5 threads. 1st thread will sum up numbers from 1-200 2nd thread will sum up numbers from 201 - 400 ... 5th thread will...
JavaScript 1. FizzBuzz Submit js file with functioning code Write a program that uses console.log to...
JavaScript 1. FizzBuzz Submit js file with functioning code Write a program that uses console.log to print all the numbers from 1 to 120, with two exceptions. For numbers divisible by 4, print "Fizz" instead of the number, and for numbers divisible by 10 (and not 4), print "Buzz" instead. When you have that working, modify your program to print "FizzBuzz", for numbers that are divisible by both 4 and 10 (and still print "Fizz" or "Buzz" for numbers divisible...
. You must use Excel (submit either a pdf, word or Excel file only). . You...
. You must use Excel (submit either a pdf, word or Excel file only). . You must identify the 5 steps (you must address each in detail). Problem: Use the given data to complete a t-test using Excel. Question: Is there a difference in group means between the number of words spelled correctly for two groups of fourth graders? Group Assignment Score 1 3 1 4 1 10 2 14 2 7 2 8 2 10 2 15 2 9...
Write a single MATLAB function called numdiff, saved in a file called numdiff.m. Submit that single...
Write a single MATLAB function called numdiff, saved in a file called numdiff.m. Submit that single file here in Canvas. To make grading easier, please do the following: • Close your function with "end". • Don't have your function print anything to the console; just return the output. To accomplish this: o Put a semicolon ";" at the end of each statement. o Put a percent "%" before each disp or fprintf statement. The function numdiff should take the following...
Using the R package to answer the following two questions. You MUST submit your R code...
Using the R package to answer the following two questions. You MUST submit your R code for analysis. 2. Below are heights for a simple random sample of n = 15 young trees (in cm). (50 pts) 27, 33, 33, 34, 36, 37, 39, 40, 40, 41, 41, 42, 44, 46, 47. (a) Test the hypothesis that the mean tree height is equal to 38 cm. (b) Calculate the 95% confidence interval for the population mean of young trees. (c)...
a) Submit a copy of your dataset along with a file that contains your answers to...
a) Submit a copy of your dataset along with a file that contains your answers to all of the following questions. b) What the mean and Standard Deviation (SD) of the Close column in your data set? c) If a person bought 1 share of Google stock within the last year, what is the probability that the stock on that day closed at less than the mean for that year? Hint: You do not want to calculate the mean to...
Submit your solution to the problem in an Excel file. Explain your answer as necessary and...
Submit your solution to the problem in an Excel file. Explain your answer as necessary and be sure your calculations are clearly shown. ABC Corporation is large and profitable. This year it is considering buying factory equipment for $100,000,000. ABC’s cost of capital is 7%. Required: a) What is the after-tax cost of the equipment if it qualifies for 100% bonus depreciation? b) What is the after-tax cost of the equipment if it is depreciated using MACRS (7 year recovery...
Answer all the items. To submit your exam you can either upload the file or upload...
Answer all the items. To submit your exam you can either upload the file or upload images of the pages with the handwritten answers (take photos or scan them). 1. T / F In double entry accounting, recorded financial events/transactions are self-balancing with debits equaling credits. 2. Fill out the basic accounting equation: ___________________ = _________________________ + ____________________ 3. Make the accounting entries for payment of medical supplies of $250. ACCT Debit Credit ______________ ___________ ___________ ______________ ___________ ___________ 4....
JavaScript Task Load three images of colorful fall leaves and using functions with parameters do the...
JavaScript Task Load three images of colorful fall leaves and using functions with parameters do the following. (Remember you can call the same function multiple times sending the function different values.) When you move the mouse over the first image, have the second image change to a pumpkin. When you move the mouse off of the first image, have the second image change back to the original leaves. When you move the mouse over the second image, have the third...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT