Question

In: Computer Science

In python language do thee following: Some password scheme is designed such that the password must...

In python language do thee following:

Some password scheme is designed such that the password must start with a special symbol in “$” “@” or “!” followed by four letters that could be in a..z followed by a similar special symbol followed by three letters in A..Z followed by a single digit. Write a program that takes from the user a string, and verifies whether the string abides by this password scheme. Do this once using regular expressions. Another time without using regular expressions.

Solutions

Expert Solution

Lets see the case where we don't use RegEx. In this case, we need to verify each character of the input password falls in the expected set of characters.

So, we check these characters as we go on traversing the password string.

To check the password characters against the asked character sets, we need to define these sets of Capital and small letters, and special characters as well.

If any of these checks fail, the password is not proper.

CODE:

alphaCapital ="QWERTYUIOPASDFGHJKLZXCVBNM"

alphaSmall = "qwertyuiopasdfghjklzxcvbnm"

splChar = "!@#$%^&*()_"

pwd = input("Enter the password: ")

isCorrect = 1

if pwd[0] not in splChar: #if firstt char is not special

isCorrect=0

print("first spl")

for j in range(1,5):

if pwd[j] not in alphaSmall: #check if not small

isCorrect = 0

print("small alpha not found")

if pwd[5] not in splChar: #checking if not a special char

isCorrect = 0

print("second spl")

for k in range(6,9): #traversing next 3 chars

if pwd[k] not in alphaCapital: #checking if not capital

isCorrect =0

print("Capital not found")

if not pwd[9].isdigit(): #checking if not a digit

isCorrect = 0

print("no digit last")

if isCorrect == 0:

print("Password is not proper!")

else:

print("Password is proper.")

OUTPUT:

Now, less consider the RegEx approach.

In this we will define a pattern as asked in the question.

The pattern will include character classes, their position, and their frequencies in the password string.

We then match the input password against this pattern.

CODE:

import re

pwd = input("Enter the password: ")

#matching the password entered with the regex:

isCorrect = re.search("^[!@#$%^&*()_][a-z]{4}[!@#$%^&*()_][A-Z]{3}[0-9]$", pwd)


if isCorrect:

print("Password is proper!")

else:

print("Password is not proper.")

CODE and OUTPUT:


Related Solutions

Write a simple Calculator program using Scheme programming language. It should be able to do following...
Write a simple Calculator program using Scheme programming language. It should be able to do following operations: "+", "-", " * *, "/". the format when using the calculator function should be (calculator(operand1 operation operand2)) -> (calculator(2 + 5)) should give the output of 7.
An organization has the following password policies: - password must be at least 16 characters long...
An organization has the following password policies: - password must be at least 16 characters long - three failed login attempts will lock the account for 5 minutes - password must have one uppercase letter, one lowercase letter, and one non alphanumeric symbol a database server was recently breached, and the incident Response Team suspect the passwords were compromised. Users with permission on the database server were forced to change their passwords for that server. Unauthorised and suspicious logins are...
You must write each of the following scheme functions. You must use only basic scheme functions...
You must write each of the following scheme functions. You must use only basic scheme functions do not use third-party libraries to support any of your work. Do not use any function with side effects. Write a function (merge-sorter L1) that takes list-of-integers L1 and returns all elements of L1 in sorted order. You must use a merge-sort technique that, in the recursive case, a) splits L1 into two approximately-equal-length lists, b) sorts those lists, and then c) merges the...
You must write each of the following scheme functions. You must use only basic scheme functions...
You must write each of the following scheme functions. You must use only basic scheme functions do not use third-party libraries to support any of your work. Do not use any function with side effects. This problem need to use DrRacket software. Racket Language. Write a function named (forget-n L1 N) that returns the elements of L1 except for the first N. If N is negative, return all elements. If N exceeds the length of L1 return the empty list....
You must write each of the following scheme functions. You must use only basic scheme functions...
You must write each of the following scheme functions. You must use only basic scheme functions do not use third-party libraries to support any of your work. Do not use any function with side effects. This problem needs to use DrRacket software. Racket Language. Write a function (indices L1 X) that takes a list of elements L1 and an element X. The function returns a list of the indices in L1 that contain X. See the following examples for clarification....
You must write each of the following scheme functions. You must use only basic scheme functions,...
You must write each of the following scheme functions. You must use only basic scheme functions, do not use third-party libraries to support any of your work. Do not use any function with side effects. This problem need to use DrRacket software. Racket Language. Write a function named (first-n L1 N) that returns the first N elements of L1. If N is negative, return the empty list. If N exceeds the length of L1 return all elements of L1. (first-n...
You must write each of the following scheme functions. You must use only basic scheme functions...
You must write each of the following scheme functions. You must use only basic scheme functions do not use third-party libraries to support any of your work. Do not use any function with side effects. This problem need to use DrRacket software. Racket Language. Write a function (join-together L1 L2) that takes a sorted list (ascending) of integers L1 and a sorted list of elements L2 and returns a sorted list containing all elements of both L1 and L2. See...
You must write each of the following scheme functions. You must use only basic scheme functions...
You must write each of the following scheme functions. You must use only basic scheme functions do not use third-party libraries to support any of your work. Do not use any function with side effects. Write a function (indices L1 X) that takes a list of elements L1 and an element X. The function returns a list of the indices in L1 that contain X. See the following examples for clarificaton. (indices '(a b c a e f a) 'a')...
You must write each of the following scheme functions. You must use only basic scheme functions...
You must write each of the following scheme functions. You must use only basic scheme functions do not use third-party libraries to support any of your work. Do not use any function with side effects. Write a function named (list-replace ALIST SYM VAL) that accepts a list of elements and returns that list where all SYM's (a single symbol) have been replaced by the VAL (some scheme value). The replacement must occur even within nested lists. For example: (list-replace '(a...
Write a program in Python language which will do the following: Write a program to prompt...
Write a program in Python language which will do the following: Write a program to prompt the user to enter a company name, city, state and zip code. Create a dictionary with the data. Output the dictionary. Then remove the city from the dictionary and output again.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT