forked from 0xcomposure/OdooUserPassChanger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OdooUserPassChanger-python2.py
45 lines (38 loc) · 1.42 KB
/
OdooUserPassChanger-python2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from passlib.context import CryptContext
import psycopg2
import getpass
import signal
import sys
def handler(signum, frame): # Function to print a message when Ctrl+C.
print '\nLeaving the application...\nGood bye!'
sys.exit(0)
signal.signal(signal.SIGINT, handler)
"""
variables to get DB connection data,
user you want to change de password
and the new password for the user.
"""
dbname = raw_input("Enter the DB name: ")
dbuser = raw_input("Enter the DB user: ")
dbpass = getpass.getpass("Enter the password for " + dbuser + ": ")
dbhost = raw_input("Enter the host[localhost]: ") or "localhost"
usertoupdate = raw_input("Enter the user you want to change the password: ")
newpass = getpass.getpass("Enter the new password for "+usertoupdate+": ")
newpass_crypt = CryptContext(['pbkdf2_sha512']).encrypt(newpass)
"""
try to connect with the DB and make the update with the new password.
if the connection failed return a message.
"""
try:
conn = psycopg2.connect("dbname='" + dbname + "' user='" + dbuser + "\
' host='" + dbhost + "\
' password='" + dbpass + "'")
print "Opened database successfully"
cur = conn.cursor()
cur.execute("UPDATE res_users SET password_crypt = '"+newpass_crypt+"\
' WHERE login = '"+usertoupdate+"'")
conn.commit()
conn.close()
print "Password for "+usertoupdate+" has been updated successfully"
except:
print "Unable to connect to the database"