Question

In: Computer Science

To be done in Python 3.7 Some Web sites impose certain rules for passwords. Write a...

To be done in Python 3.7

Some Web sites impose certain rules for passwords. Write a function that checks whether a string is a valid password. Suppose the password rules are as follows:

  • A password must have at least eight characters.

  • A password must consist of only letters and digits.

  • A password must contain at least two digits.

Write a program that prompts the user to enter a password and displays valid password if the rules are followed or invalid password otherwise.

  • A password cannot contain the word ‘password’
  • A password cannot end with ‘123’

Your program should define a class called Password, which is in its own file called password.py. You should have another file called assn13-task2.py that has code the creates and uses a Password object. All input and print functions should be in in this file. Your program will prompt the user for a password, and after completing will ask the user if they want to enter another. The program should only ever create one instance of Password. Your Password class should have at least the following:

  • setPassword() method
  • isValid() method
    • This should return a Boolean
  • getErrorMessage() method
    • This should return a string that indicates all problems with the password
    • It should be called if isValid() returns False
    • The isValid() method can generate this string as it tests each password requirement
      • Hint: create a private instance variable called __message to save it
    • Example return string
      • “must have 8 characters\nmust have at least 2 digits\ncannot end in 123”

Solutions

Expert Solution

password.py file:

Code for the above password.py file:

class Password:
    __message = ''
    errorMessage = []
    def setPassword(self,passString):
        self.__message = passString
        return self.isValid()

    def getErrorMessage(self):
        temp = self.errorMessage.copy()
        self.errorMessage = []
        return temp

    def isValid(self):
        v=0
        if self.__message == 'password':
            self.errorMessage.append('A password cannot contain the word ‘password’')
            v=1
        if len(self.__message)>8:
            if self.__message[-3:] == '123':
                self.errorMessage.append('A password cannot end with ‘123’')
                v=1
        else:
            self.errorMessage.append('A password must have at least eight characters.')
            v=1
        if not self.__message.isalnum():
            self.errorMessage.append('A password must consist of only letters and digits.')
            v=1
        if sum(character.isdigit() for character in self.__message) < 2:
            self.errorMessage.append('A password must contain at least two digits.')
            v=1
        return True if v==0 else self.getErrorMessage()

assn13-task2.py file:

Code for the above assn13-task2.py file:

from Password  import Password
p = Password()
exit = 1
while(exit!=0):
    print('\nEnter password: ', end="")
    res = p.setPassword(input().strip())
    if res == True:
        print('Entered String is a Valid Password')
    else:
        for i in res:
            print(i)
    print('\nDo you want to check another password(1=>yes / 0=>no): ',end=" ")
    exit = int(input())

Output for running the  assn13-task2.py file:


Related Solutions

Task 1: Some websites impose certain rules for passwords. Write a program that ask the user...
Task 1: Some websites impose certain rules for passwords. Write a program that ask the user to enter a password and checks whether a string (Use input validation to make sure the user enters the correct password and then print it.) is a valid password. Suppose the password rules are as follows: • A password must have list a least 10 characters. • A password must consist of only letters and digits. • A password must contain at least two...
5. On the web view each of the following web sites. Write a short summary of...
5. On the web view each of the following web sites. Write a short summary of your understanding of each. rumkin.com program to test several types of coding. Rate each one on strength. https://youtu.be/SAAflrIp__E https://youtu.be/-yFZGF8FHSg https://youtu.be/uK8DXrTEK-U BY SEEING THE YOUTUBE LINK VIDEOS WRITE A SHORT SUMMARY OF YOUR UNDERSTANDING FOR ALL THOSE 3 LINKS
Please use the python 3.7 for this assigments Q1 Write a program that accepts the lengths...
Please use the python 3.7 for this assigments Q1 Write a program that accepts the lengths of three sides of a triangle as inputs. The program output should indicate whether or not the triangle is an equilateral triangle. Q2 Write a program that accepts the lengths of three sides of a triangle as inputs. The program output should indicate whether or not the triangle is a right triangle. Recall from the Pythagorean theorem that in a right triangle, the square...
THIS is to be done in python! Splitting the Bill- An exercise in input validation Write...
THIS is to be done in python! Splitting the Bill- An exercise in input validation Write a python program called splitBill.py that works as follows: • (10 points) Allow the user to input a bill amount, a tip percent, and the number of people in their party. o Input validation: Make sure to validate the input data. Allow the user to reenter inputs until they enter values which are valid. ▪ Make it easy on the user: To leave a...
LANGUAGE PYTHON 3.7 Write a collection class named "Jumbler". Jumbler takes in an optional list of...
LANGUAGE PYTHON 3.7 Write a collection class named "Jumbler". Jumbler takes in an optional list of strings as a parameter to the constuctor with various strings. Jumbler stores random strings and we access the items based on the methods listed below. Jumbler supports the following methods: add() : Add a string to Jumbler get() : return a random string from Jumbler max() : return the largest string in the Jumbler based on the length of the strings in the Jumbler....
Python 3.7: Write the following decorators and apply them to a single function (applying multiple decorators...
Python 3.7: Write the following decorators and apply them to a single function (applying multiple decorators to a single function): 1. The first decorator is called strong and has an inner function called wrapper. The purpose of this decorator is to add the html tags of <strong> and </strong> to the argument of the decorator. The return value of the wrapper should look like: return “<strong>” + func() + “</strong>” 2. The decorator will return the wrapper per usual. 3....
Python 3.7: 1. Write a generator expression that repeats each character in a given string 4...
Python 3.7: 1. Write a generator expression that repeats each character in a given string 4 times. i.e. given “gone”, every time you call the next method on the generator expression it will display “gggg”, then “oooo”, … etc and instantiate it to an object called G.  G = (…..) # generatorExpression object 2. Test and verify that iter(G) and G are the same things. What does this tell you about the nature of a Generator object/expression? 3. Assign Iter(G) to...
Python 3.7: Give the following sample code, write the following programs: • An iterator class called...
Python 3.7: Give the following sample code, write the following programs: • An iterator class called Iteratefirstn that implements __iter__() and __next__() methods where next method should raise an exception for the cur index if it is passed the last element otherwise set cur index to the next index and advance the index by one, i.e. cur, num = num, num+1. Instantiate the class to calculate the sum of 1000000 elements similar to the example. • Instead of implementing the...
Write a paragraph conducting an online analysis of advertising used on various web sites. Analyze how...
Write a paragraph conducting an online analysis of advertising used on various web sites. Analyze how these promotions are used to attract viewers to the site, to generate advertising revenue, to motivate online buying, or for other promotional goals.
USING PYTHON 3.7 AND USING def functions. Write a function called GPA that calculates your grade...
USING PYTHON 3.7 AND USING def functions. Write a function called GPA that calculates your grade point average (GPA) on a scale of 0 to 4 where A = 4, B = 3, C = 2, D = 1, and F = 0. Your function should take as input two lists. One list contains the grades received in each course, and the second list contains the corresponding credit hours for each course. The output should be the calculated GPA. To...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT