Beispiel #1
0
 def register_login_info(self, website, username, password):
     credentials = Credentials(website, username, password)
     """If the user doesn't enter a password the function generates a safe one"""
     if credentials.password == '':
         new_password = PasswordGenerator()
         credentials.password = new_password.generate_password()
     self.credentials.append(credentials)
     self.create_file()
     return credentials
Beispiel #2
0
 def makePassword(self):
     p = PasswordGenerator(int(self.passLen.get()))
     self.__pword.set(p.genPassword())
     print(self.__pword.get())
                userCata[0].append(reason)
                username=input("What is the user name for it?\n")
                userCata[1].append(username)
                password=input("Please enter the password then if you don't know a password then type 'create'\n")
                if password!="create":      #if the user has their own password it will go through the password checker and if it doesn't meet the requirements then it will ask for a password again or they have the option of doing a random password
                    while password!="create":
                        pc=PasswordChecker(password)
                        if "False" in str(pc):
                            print("That password does not meet the requirements\n")
                            password=input("Please enter the password then if you don't know a password then type 'create'\n")
                        else:               #if the password meets the requirements then it will append it to the list
                            userCata[2].append(password)
                            print(homePasswords)
                            break
                else:       #if the user puts create then it will call the password generator class and append the random password to the list
                    pg=PasswordGenerator()
                    userCata[2].append(pg.__str__())
                    print(userCata)
                

            if ui==("home"):        #if the user wants to put passwords in the home section it will ask for what the password is for, the username,and the password and append that all to the home list
                reason=input("What is this password for?\n")
                homePasswords[0].append(reason)
                username=input("What is the user name for it?\n")
                homePasswords[1].append(username)
                password=input("Please enter the password then if you don't know a password then type 'create'\n")
                if password!="create":      #if the user has their own password it will go through the password checker and if it doesn't meet the requirements then it will ask for a password again or they have the option of doing a random password
                    while password!="create":
                        pc=PasswordChecker(password)
                        if "False" in str(pc):
                            print("That password does not meet the requirements\n")
Beispiel #4
0
    def do_GET(self):
        rootdir = os.path.dirname(
            os.path.abspath(__file__)) + '/public'  # file location
        try:
            if (self.path.startswith('/api') is
                    False) and self.path.endswith('.html'):
                print(rootdir + self.path)
                f = open(rootdir + self.path, 'r')  # open requested file

                # send code 200 response
                self.send_response(200)

                # send header first
                self.send_header('Content-type', 'text/html')
                self.end_headers()

                # send file content to client
                self.wfile.write(f.read().encode())
                f.close()
            elif urlparse(self.path).path == '/api/password':
                query = parse_qs(urlparse(self.path).query)
                length = int(query['length'][0])
                digits = query['digits'][0]
                specials = query['specials'][0]

                if length < 4:
                    self.send_response(500)
                    self.send_header('Content-type', 'text/html')
                    self.end_headers()
                    self.wfile.write(
                        "Password has to composed of at least 4 characters!".
                        encode())
                else:
                    self.send_response(200)
                    self.send_header('Content-type', 'text/html')
                    self.end_headers()

                    self.wfile.write(
                        'Length :\t{}<br>Digits :\t{}<br>Specials :\t{}<br><br>Password :\t'
                        .format(length, digits, specials).encode())

                    self.wfile.write("{}".format(
                        passGenerator(length, digits, specials)).encode())
            elif urlparse(self.path).path == '/api/password2':
                query = parse_qs(urlparse(self.path).query)
                length = 16
                if 'length' in query:
                    length = int(query['length'][0])
                lowercase = False
                if 'lowercase' in query:
                    lowercase = query['lowercase'][0] == 'on'
                uppercase = False
                if 'uppercase' in query:
                    uppercase = query['uppercase'][0] == 'on'
                digits = False
                if 'digits' in query:
                    digits = query['digits'][0] == 'on'
                specials = False
                if 'specials' in query:
                    specials = query['specials'][0] == 'on'

                if length < 4:
                    self.send_response(500)
                    self.send_header('Content-type', 'text/html')
                    self.end_headers()
                    self.wfile.write(
                        "Password has to composed of at least 4 characters!".
                        encode())
                else:
                    self.send_response(200)
                    self.send_header('Content-type', 'text/html')
                    self.end_headers()

                    self.wfile.write(
                        'Length :\t{}<br>Digits :\t{}<br>Specials :\t{}<br><br>Password :\t'
                        .format(length, digits, specials).encode())

                    passgen = PasswordGenerator()
                    passgen.set(lowercase, uppercase, digits, specials)

                    self.wfile.write(passgen.generate(length).encode())

            return

        except IOError:
            self.send_error(404, 'file not found')
        return
Beispiel #5
0
from PasswordGenerator import PasswordGenerator

if __name__ == "__main__":

    print("Entering Password Generator")
    passwordLen = int(
        input("Please enter the length you would like the password to be : "))
    print("Generating password with length %s" % (passwordLen))
    print("-------------------------------------------")

    generator = PasswordGenerator(passwordLen)
    generator.determine()
from PasswordGenerator import PasswordGenerator
import os

print("Welcome to PassGru\n".center(os.get_terminal_size().columns))
User_In = int(input("[1] Sava a new password\n[2] Generate a new password: "******"How many letter do you want in you Password(Ex. 15): "))
    PasswordGenerator.__PasswordGenerate__(Char)
else:
    print("Sorry Worry input")
Beispiel #7
0
    def test_generatePassword(self):

        # Test cases
        testCases = [{
            "length": 10,
            "characters": True,
            "numbers": True,
            "specialChar": True,
            "uppercase": True,
            "lowercase": True
        }, {
            "length": 30,
            "characters": False,
            "numbers": True,
            "specialChar": False,
            "uppercase": False,
            "lowercase": False
        }, {
            "length": 15,
            "characters": False,
            "numbers": True,
            "specialChar": False,
            "uppercase": True,
            "lowercase": False
        }, {
            "length": 15,
            "characters": True,
            "numbers": True,
            "specialChar": True,
            "uppercase": True,
            "lowercase": True
        }]
        for testCase in testCases:
            self.passwordGen = PasswordGenerator(testCase['length'],
                                                 testCase['characters'],
                                                 testCase['numbers'],
                                                 testCase['specialChar'],
                                                 testCase['uppercase'],
                                                 testCase['lowercase'])
            self.assertTrue(type(self.passwordGen.generatePassword()) is str)
            passwordToTest = self.passwordGen.generatePassword()
            print("Testcase: ", testCase, "Testing password: ", passwordToTest)
            # Assert that passwordToTest is alphabethical if testCase numbers is not True and vice versa.
            self.assertEqual(passwordToTest.isalpha(), not testCase['numbers'])
            # Assert that passwordToTest is lowercase if testCase uppercase is not True and testCase lowercase is True and vice versa.
            self.assertEqual(
                passwordToTest.islower(), not testCase['uppercase']
                and testCase['lowercase'])
            # Assert that the final length of the password is the same as the length provided
            self.assertEqual(len(passwordToTest), testCase['length'])
        # Assert that setting all settings to False will throw an error
        print('Expect Exception with all settings set to False:')
        with self.assertRaises(Exception):
            self.passwordGen = PasswordGenerator(20, False, False, False,
                                                 False, False)
            self.passwordGen.generatePassword()
        # Assert that setting all settings to False will throw an error
        print('Expect no Exception with all settings set to True:')
        self.passwordGen = PasswordGenerator(20, True, True, True, True, True)
        self.passwordGen.generatePassword()
        not self.assertRaises(Exception)
Beispiel #8
0
class TestPasswordGenerator(unittest.TestCase):

    # Instance of PasswordGenerator class with default values
    # length=10, characters=True, numbers=True, specialChar=True, uppercase=True, lowercase=True
    passwordGen = PasswordGenerator()

    def test_constructor(self):
        self.assertIsInstance(self.passwordGen, PasswordGenerator)
        # TODO: More tests here?

    def test_length(self):

        # Test cases for expected exceptions.
        failTestCases = [-10, 0, 9, 31, "string", 0.1, None]
        for testcase in failTestCases:
            print("Expect exception with value:", testcase)
            with self.assertRaises(Exception):
                self.passwordGen.length = testcase

        # Test cases for expected success.
        successTestCases = [10, 15, 30]
        for testcase in successTestCases:
            print("Expect success with value:", testcase)
            self.passwordGen.length = testcase
            self.assertEqual(testcase, self.passwordGen.length)
            not self.assertRaises(Exception)

    def test_characters(self):

        # Test cases for expected exceptions.
        failTestCases = [1, "string", 0.1, None]
        for testcase in failTestCases:
            print("Expect exception with value:", testcase)
            with self.assertRaises(Exception):
                self.passwordGen.characters = testcase
                self.passwordGen.numbers = testcase
                self.passwordGen.specialChar = testcase
                self.passwordGen.uppercase = testcase
                self.passwordGen.lowercase = testcase

        # Test cases for expected success.
        successTestCases = [True, False]
        for testcase in successTestCases:
            print("Expect success with value:", testcase)
            self.passwordGen.characters = testcase
            self.assertEqual(testcase, self.passwordGen.characters)
            not self.assertRaises(Exception)

            self.passwordGen.numbers = testcase
            self.assertEqual(testcase, self.passwordGen.numbers)
            not self.assertRaises(Exception)

            self.passwordGen.specialChar = testcase
            self.assertEqual(testcase, self.passwordGen.specialChar)
            not self.assertRaises(Exception)

            self.passwordGen.uppercase = testcase
            self.assertEqual(testcase, self.passwordGen.uppercase)
            not self.assertRaises(Exception)

            self.passwordGen.lowercase = testcase
            self.assertEqual(testcase, self.passwordGen.lowercase)
            not self.assertRaises(Exception)

    def test_generatePassword(self):

        # Test cases
        testCases = [{
            "length": 10,
            "characters": True,
            "numbers": True,
            "specialChar": True,
            "uppercase": True,
            "lowercase": True
        }, {
            "length": 30,
            "characters": False,
            "numbers": True,
            "specialChar": False,
            "uppercase": False,
            "lowercase": False
        }, {
            "length": 15,
            "characters": False,
            "numbers": True,
            "specialChar": False,
            "uppercase": True,
            "lowercase": False
        }, {
            "length": 15,
            "characters": True,
            "numbers": True,
            "specialChar": True,
            "uppercase": True,
            "lowercase": True
        }]
        for testCase in testCases:
            self.passwordGen = PasswordGenerator(testCase['length'],
                                                 testCase['characters'],
                                                 testCase['numbers'],
                                                 testCase['specialChar'],
                                                 testCase['uppercase'],
                                                 testCase['lowercase'])
            self.assertTrue(type(self.passwordGen.generatePassword()) is str)
            passwordToTest = self.passwordGen.generatePassword()
            print("Testcase: ", testCase, "Testing password: ", passwordToTest)
            # Assert that passwordToTest is alphabethical if testCase numbers is not True and vice versa.
            self.assertEqual(passwordToTest.isalpha(), not testCase['numbers'])
            # Assert that passwordToTest is lowercase if testCase uppercase is not True and testCase lowercase is True and vice versa.
            self.assertEqual(
                passwordToTest.islower(), not testCase['uppercase']
                and testCase['lowercase'])
            # Assert that the final length of the password is the same as the length provided
            self.assertEqual(len(passwordToTest), testCase['length'])
        # Assert that setting all settings to False will throw an error
        print('Expect Exception with all settings set to False:')
        with self.assertRaises(Exception):
            self.passwordGen = PasswordGenerator(20, False, False, False,
                                                 False, False)
            self.passwordGen.generatePassword()
        # Assert that setting all settings to False will throw an error
        print('Expect no Exception with all settings set to True:')
        self.passwordGen = PasswordGenerator(20, True, True, True, True, True)
        self.passwordGen.generatePassword()
        not self.assertRaises(Exception)