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
#21
Read this:

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

In particular the part about subprocess.run()

I've seen lots of times users set shell=True because they are used to running the command they want to run() in a shell. That is not why you set shell=True. Shell should normally be False.
Reply
#22
thanks dean, where would i put this code in my script

     
@app.route('/password', methods=['GET', 'POST'])
def password():
    form = PasswordForm()
    if request.method == 'POST' and form.validate():
        return '<h1>The username is {}. The old password is {}. the new password is {}. changing for domain {}'.format(form.un.data, form.op.data, form.cnp.data, form.dom.data)
!!!!!!!!!!!!!!!!WOULD I PUT IT HERE!!!!!!!!!
    return render_template('password.html', form=form)

if __name__ == '__main__':
    app.run(debug=True)
Reply
#23
im getting this error on cmd when i run it, ive put the code in the location i have said above

im just doing a test so thats why ive put "hostname" not the actual password reset command

c:\python\password.py:48: SyntaxWarning: invalid escape sequence '\W'
  subprocess.run('C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe hostname', shell=False)
 * Debugger is active!
 * Debugger PIN: 113-933-542
Reply
#24
Read the documentation. You need to separate the arguments from the command, not have all in one string. You can do it the way you have, but then you need shell = True.

\ is used to start escape sequences for including non-visible characters in a string. Like \n for a new line. Use a raw string or \\ to make them just a backslash
Reply
#25
(Jun-22-2024, 11:58 AM)deanhystad Wrote: Read the documentation. You need to separate the arguments from the command, not have all in one string. You can do it the way you have, but then you need shell = True.

\ is used to start escape sequences for including non-visible characters in a string. Like \n for a new line. Use a raw string or \\ to make them just a backslash

ok done a test and it works so when i get home tonight i will try it in my script

import subprocess

subprocess.run('C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe ipconfig', shell=True)
ok ive put this in my script but what line do i put it in my script as its not working as expected, i only want it to run ie show the ipconfig details when they hit the submit button and all the validations are good

@app.route('/password', methods=['GET', 'POST'])
def password():
    form = PasswordForm()
    if request.method == 'POST' and form.validate():
        return '<h1>The username is {}. The old password is {}. the new password is {}. changing for domain {}'.format(form.un.data, form.op.data, form.cnp.data, form.dom.data)
        return subprocess.run('C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe ipconfig', shell=True)
    return render_template('password.html', form=form)

if __name__ == '__main__':
    app.run(debug=True)
Reply
#26
tbh il make a new thread about this as this has got nothing to do with regex now
Reply
#27
Regex can definitely be tricky! For the admin part, you might want to use something like (?=.*admin) to check if "admin" is part of the password and then invalidate it if found. To ensure the password meets certain criteria (like length, uppercase, digits, and special characters), you can use regex patterns like ^(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{12,}$. Combining these checks should help you validate the password effectively.
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,589 Apr-24-2024, 05:47 AM
Last Post: Bronjer
  try catch not working? korenron 2 993 Jan-15-2023, 01:54 PM
Last Post: korenron
  python-docx regex: replace any word in docx text Tmagpy 4 2,453 Jun-18-2022, 09:12 AM
Last Post: Tmagpy
  Multiprocessing queue catch get timeout Pythocodras 1 2,559 Apr-22-2022, 06:01 PM
Last Post: Pythocodras
  twisted: catch return from sql wardancer84 0 1,599 Sep-08-2021, 12:38 PM
Last Post: wardancer84
  how to catch schema error? maiya 0 1,966 Jul-16-2021, 08:37 AM
Last Post: maiya
  is this a good way to catch exceptions? korenron 14 5,047 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,626 Dec-03-2020, 04:46 PM
Last Post: bowlofred
  try catch question ,get data from main code korenron 7 3,386 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