Python Forum
equalto validator doesnt work
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
equalto validator doesnt work
#1
hi all,

my code below doesnt work ie the new password and confirm new password, the user on the web when they click the submit button they dont get the message saying passwords dont match and i have no idea why

the length validator works fine, ive imported the modules

from wtforms.validators import InputRequired, Length, DataRequired, EqualTo, Regexp
new_password = PasswordField('New_Password', validators=[InputRequired(), Length(min=12), EqualTo('confirm_new_password', message='Passwords must match')])
    confirm_new_password = PasswordField('Confirm_New_Password')
thanks,
rob
Reply
#2
If your validator is invalid: Do it yourself!

import re

# password must contain at least 3 CAPITAL LETTERS
# password must contain at least 3 digits
# password must contain at least 1 small letter
def validator():
    e = re.compile(r'\A(?=[^a-z]*[a-z])(?=(?:[^A-Z]*[A-Z]){3})(?=\D*\d{3}).*')
    print('Your password MUST contain at least 1 small letter.')
    print('Your password MUST contain at least 3 capital letters and at least 3 digits.')
    print('You password may contain spaces and any or all of these: @#$%^&* to make it safer.')
    pw1 = input('Please enter a password you can remember. ')
    while not e.match(pw1):
        print('Your password MUST contain at least 3 capital letters and at least 3 digits.')
        print('You password may contain spaces and any or all of these: @#$%^&* to make it safer.')
        pw1 = input('Please enter a password you can remember. ')
    pw2 = input('Please enter the password you just wrote again. ')    
    while not pw1 == pw2:
        print('Looks like you have problems with simple instructions. Let\'s try that again!')
        pw1 = input('Please enter a password you can remember. ')
        while not e.match(pw1):
            print('Your password MUST contain at least 3 capital letters and at least 1 digit.')
            print('You password may contain any or all of these: @#$%^&* to make it safer.')
            pw1 = input('Please enter a password you can remember. ')
        print('Now, please try to write the EXACT SAME password again, thank you.')
        print('If you can not write the same password again, this loop will never end ... ')
        pw2 = input('Please enter the password you you just wrote again. ')
    return pw1

password = validator()
Gives:

Output:
password = validator() Your password MUST contain at least 1 small letter. Your password MUST contain at least 3 capital letters and at least 3 digits. You password may contain spaces and any or all of these: @#$%^&* to make it safer. Please enter a password you can remember. Pedro Juan 1988 Your password MUST contain at least 3 capital letters and at least 3 digits. You password may contain spaces and any or all of these: @#$%^&* to make it safer. Please enter a password you can remember. Juan Pedro Sanchez 1999 Please enter the password you just wrote again. Juan Pedro Sanchez 1999
Although, I would rather use PHP to do this on a register.html page!

But I don't know how to use Python for webpages!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  print doesnt work in a function ony 2 471 Mar-11-2024, 12:42 PM
Last Post: Pedroski55
  Pydoc documentation doesnt work Cosmosso 5 4,655 Nov-25-2023, 11:17 PM
Last Post: vidito
  pip install requests doesnt work misodca 8 7,535 Jul-07-2023, 08:04 AM
Last Post: zyple
  Ldap3 Python print(conn.entries) doesnt work ilknurg 15 6,343 Dec-28-2022, 11:22 AM
Last Post: shad
  pip install pystyle doesnt work person_probably 2 2,346 Sep-23-2022, 02:59 PM
Last Post: person_probably
  Why doesnt chunk generation work? LotosProgramer 1 2,048 Apr-02-2022, 08:25 AM
Last Post: deanhystad
  if conditions in the for indentation doesnt work ? Sutsro 6 4,143 Jun-15-2021, 11:45 PM
Last Post: bowlofred
  I have two Same Code but One of them Doesnt Work beginner721 6 3,294 Jan-22-2021, 10:56 PM
Last Post: beginner721
  code doesnt return anything ofrihemo 3 2,191 Jun-30-2020, 05:14 PM
Last Post: ofrihemo
  BEGINNER: My calculator doesnt work iskov 5 3,386 Oct-09-2019, 07:45 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020