Beispiel #1
0
    def clean(self):
        cleaned_data = super(SignUpForm, self).clean()
        pwd = cleaned_data.get("password1")
        if pwd:
            password_validation.validate_password(pwd)

        return cleaned_data
Beispiel #2
0
def main():
    repository = UsersRepository()
    while True:
        action = input("Select action: \n 1-register 2-log in 3- quit ")
        if action == "1":
            name = input("Please enter your username ")
            if repository.contains(name):
                print("Username is already taken. Please try again")
                continue
            mail = input("Please enter your e-mail address ")
            password = input(
                "Please select your password. Password must contains at least 8 character and one number. "
            )
            if not validate_password(password):
                print("Password does not meet specified requirements")
                continue
            confirmation = input("Confirm your password ")
            if password != confirmation:
                print("Wrong password. Try again")
                continue
            if repository.add(name, encode_password(password), mail):
                print("User created successfully")
                send_mail(mail, name)
        elif action == "2":
            name = input("Please enter your username ")
            password = input("Please select your password ")
            if repository.validate(name, encode_password(password)):
                print("You have been logged in successfully")
            else:
                print("Invalid username or password")
        elif action == "3":
            print("See you soon")
            return
        else:
            print("Invalid action. Try again")
    def test_validate_password(self):
        self.assertIsNone(validate_password('sufficiently-long'))
        msg_too_short = 'This password is too short. It must contain at least 12 characters.'

        with self.assertRaises(ValidationError, args=['This password is too short.']) as cm:
            validate_password('django4242')
        self.assertEqual(cm.exception.messages, [msg_too_short])
        self.assertEqual(cm.exception.error_list[0].code, 'password_too_short')

        with self.assertRaises(ValidationError) as cm:
            validate_password('password')
        self.assertEqual(cm.exception.messages, ['This password is too common.', msg_too_short])
        self.assertEqual(cm.exception.error_list[0].code, 'password_too_common')

        self.assertIsNone(validate_password('password', password_validators=[]))
Beispiel #4
0
    def test_validate_password(self):
        self.assertIsNone(validate_password('sufficiently-long'))
        msg_too_short = 'This password is too short. It must contain at least 12 characters.'

        with self.assertRaises(ValidationError,
                               args=['This password is too short.']) as cm:
            validate_password('django4242')
        self.assertEqual(cm.exception.messages, [msg_too_short])
        self.assertEqual(cm.exception.error_list[0].code, 'password_too_short')

        with self.assertRaises(ValidationError) as cm:
            validate_password('password')
        self.assertEqual(cm.exception.messages,
                         ['This password is too common.', msg_too_short])
        self.assertEqual(cm.exception.error_list[0].code,
                         'password_too_common')

        self.assertIsNone(validate_password('password',
                                            password_validators=[]))
Beispiel #5
0
 def clean_password1(self):
     password1 = self.cleaned_data.get('password1')
     validate_password(password1)
     return password1