Python Forum
Regex to catch what user has put in text box
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regex to catch what user has put in text box
#11
admin is not 12 characters long and does not contain upper case letters, digits or special characters. Do you want to invalidate passwords that contain admin, like "Iamtheadministrator1! That is a different test.
    if form.un.data:
        if any(name in field.data for name in form.un.data.split()):
            raise ValidationError("Password cannot contain your first or last name")
robertkwild likes this post
Reply
#12
(Jun-13-2024, 05:44 PM)deanhystad Wrote: admin is not 12 characters long and does not contain upper case letters, digits or special characters. Do you want to invalidate passwords that contain admin, like "Iamtheadministrator1! That is a different test.
    if form.un.data:
        if any(name in field.data for name in form.un.data.split()):
            raise ValidationError("Password cannot contain your first or last name")
lets say i put in "robert.wild" in the username

in the new password field if i type in "robert" then hit submit doesnt catch it if i type in "wild" in the new password field doesnt catch it

ive done it by just addint the "."

if any (name in field.data for name in form.un.data.split(".")):
Reply
#13
how do i do a re.IGNORECASE as if you type it in capitals it doesnt catch it
Reply
#14
Quote:how do i do a re.IGNORECASE as if you type it in capitals it doesnt catch it
What do you mean? Is this real re or wtf.regexp? For re, read this:

https://docs.python.org/3/library/re.html
Reply
#15
(Jun-19-2024, 10:59 PM)deanhystad Wrote:
Quote:how do i do a re.IGNORECASE as if you type it in capitals it doesnt catch it
What do you mean? Is this real re or wtf.regexp? For re, read this:

https://docs.python.org/3/library/re.html

it for my wtf form

if form.un.data:
            if any (name in field.data for name in form.un.data.split(".", flags=re.I)):
                raise ValidationError('New password cant contain firstname or lastname')
basically if you type in your username in the new password it errors saying cant contain firstname or lastname but if they capitalise it, it lets them have that as a new password, i want to stop that
Reply
#16
Write a custom validator and you can use any re features you want.
Reply
#17
def validate_np(form, field):
        if form.un.data:
            if any (name in field.data.lower() for name in form.un.data.split(".")):
                raise ValidationError('New password cant contain firstname or lastname')
        if field.data.lower() == form.op.data.lower():
            raise ValidationError('New password cant match Current password')
this works im testing it so it lower cases the variables whether you put them in lower or upper case
Reply
#18
def validate_un(form, field):
        if not field.data == form.un.data.lower():
            raise ValidationError('Username needs to be Lowercase')
    
    def validate_np(form, field):
        if form.un.data:
            if any (name in field.data.lower() for name in form.un.data.split(".")):
                raise ValidationError('New password cant contain firstname or lastname')
        if field.data.lower() == form.op.data.lower():
            raise ValidationError('New password cant match Current password')
        if len(field.data) < 12:
            raise ValidationError('New password must be at least 12 characters')
        if not re.search(r"[0-9]", field.data):
            raise ValidationError('New password has to contain one number')
        if not re.search(r"[a-z]", field.data):
            raise ValidationError('New password has to contain one lower case character')
        if not re.search(r"[A-Z]", field.data):
            raise ValidationError('New password has to contain one upper case character')
        if not re.search(r"[\`\¬\!\"\£\$\%\^\&\*\(\)\-\_\=\+\\\|\[\]\;\'\#\,\.\/\{\}\:\@\~\<\>\?]", field.data):
            raise ValidationError('New password has to contain one special character')
        if not field.data == form.cnp.data:
            raise ValidationError('New password has to match Confirm new password')
so username needs to be lower case

is it ok to define two def commands in same script, they wont get confused with eachother will they?
Reply
#19
Custom validators are named after the field they validate. You can have as many validators as fields.
Reply
#20
ok im getting there, i dont know if this next bit is possible or not

for there current password is it possible to validate it with a powershell command to make sure it is there current password

as my main goal is to run this powershell command on my python script

Set-ADAccountPassword -Identity un -OldPassword (ConvertTo-SecureString -AsPlainText "op" -Force) -NewPassword (ConvertTo-SecureString -AsPlainText "cnp" -Force)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu BillKochman 13 1,557 Apr-24-2024, 05:47 AM
Last Post: Bronjer
  try catch not working? korenron 2 978 Jan-15-2023, 01:54 PM
Last Post: korenron
  python-docx regex: replace any word in docx text Tmagpy 4 2,443 Jun-18-2022, 09:12 AM
Last Post: Tmagpy
  Multiprocessing queue catch get timeout Pythocodras 1 2,553 Apr-22-2022, 06:01 PM
Last Post: Pythocodras
  twisted: catch return from sql wardancer84 0 1,596 Sep-08-2021, 12:38 PM
Last Post: wardancer84
  how to catch schema error? maiya 0 1,961 Jul-16-2021, 08:37 AM
Last Post: maiya
  is this a good way to catch exceptions? korenron 14 5,019 Jul-05-2021, 06:20 PM
Last Post: hussaind
  pool mysql error - not catch by try\except? korenron 1 2,256 Jul-05-2021, 11:26 AM
Last Post: ibreeden
  Regex text file to store data in list TheSithSiggi 1 1,617 Dec-03-2020, 04:46 PM
Last Post: bowlofred
  try catch question ,get data from main code korenron 7 3,380 Nov-03-2020, 09:28 AM
Last Post: korenron

Forum Jump:

User Panel Messages

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