Encrypt the password | Newbie | | Join Date: Feb 2009
Posts: 8
| |
Hai All,
Good Evening,
I'm doing a small application using python and MySQL in APPLE MACINTOSH OPERATING SYSTEM. I want to to store the password in encrypted form in the database. While retriving the password it should check the encrypted text with the plain text and it should navigate to the other form.
I have done the encrypted form, but while checking the parameters it should not check the plain text with the encrypted text. It only checks the encrypted text in the database.
This is the code I have given it. Please Check the code and if any modifications please correct it and send to me. -
#! /usr/bin/env python
-
from Tkinter import *
-
import tkMessageBox
-
import Tkinter
-
import time
-
-
-
-
curtime = ''
-
clock = Tkinter.Label(bg="tan")
-
clock.grid(row=22,column=0,columnspan=3,sticky=E)
-
-
def tick():
-
global curtime
-
newtime = time.strftime("TIME:"'%d/%m/%d %H:%M:%S')
-
if newtime != curtime:
-
curtime = newtime
-
clock.config(text=curtime)
-
clock.after(200, tick)
-
-
tick()
-
-
class GUIFramework(Frame):
-
"""This is the GUI"""
-
-
def __init__(self,master=None):
-
"""Initialize yourself"""
-
-
"""Initialise the base class"""
-
Frame.__init__(self,master)
-
-
"""Set the Window Title"""
-
self.master.title("LOGIN FORM")
-
self.master.config(bg="wheat")
-
"""Display the main window"
-
with a little bit of padding"""
-
self.grid(padx=10,pady=10)
-
self.CreateWidgets()
-
-
def CreateWidgets(self):
-
"""Create all the widgets that we need"""
-
self.config(bg="wheat")
-
self.lbText = Label(self,text="LOGIN DETAILS",bg="tan",relief="solid")
-
self.lbText.grid(row=0, column=0,sticky=NSEW,columnspan=50,pady=10)
-
-
"""Create the Text"""
-
self.lbText1 = Label(self,text="User Name:",bg="wheat",relief="groove",width=20)
-
self.lbText1.grid(row=1, column=0,sticky=W,columnspan=1)
-
-
"""Create the Entry, set it to be a bit wider"""
-
self.enText1 = Entry(self, width=25)
-
self.enText1.grid(row=1, column=1, columnspan=3,sticky=W)
-
-
self.lbText2 = Label(self, text="Password:",bg="wheat",relief="groove",width=20)
-
self.lbText2.grid(row=2, column=0,sticky=W)
-
-
self.enText2 = Entry(self,width=25,show="*")
-
self.enText2.grid(row=2, column=1, columnspan=3,sticky=W)
-
-
self.lbText3 = Label(self, text="Confirm Password:",bg="wheat",relief="groove",width=20)
-
self.lbText3.grid(row=3, column=0,sticky=W)
-
-
self.enText3 = Entry(self,width=25,show="*")
-
self.enText3.grid(row=3, column=1, columnspan=3,sticky=W)
-
-
self.btnsubmit = Button(self, text="Login",command=self.login, bg='wheat',relief="groove",width=8)
-
self.btnsubmit.grid(row=4, column=0,sticky=E,pady=10)
-
-
def login(self):
-
uname=self.enText1.get()
-
pwd=self.enText2.get()
-
cpwd = self.enText3.get()
-
try:
-
import os
-
import MySQLdb
-
import _mysql_exceptions as DB_EXC
-
from hashlib import md5
-
cxn = MySQLdb.connect(user ='root')
-
cur = cxn.cursor()
-
no = cur.execute("insert into abc.users values (%s,%s)", (uname,pwd)) # here abc is the database and users is the table name
-
new = md5
-
st = cur.execute("update abc.users set pwd=MD5(pwd) where uname=%s", (uname))
-
cur.close()
-
cxn.commit()
-
cxn.close()
-
if (no != 0):
-
tkMessageBox.showinfo("Text", "succesfully logged." )
-
else:
-
tkMessageBox.showinfo("Text", "Invalid User Name and password.")
-
except ImportError , e:
-
return None
-
-
if __name__ == "__main__":
-
guiFrame = GUIFramework()
-
guiFrame.mainloop()
Please Check the code and if there are any corrections made it and send to me. It is very urgent.
Please help me.
Thank You in advance.
Warm Regards
Srinivas
|  | Moderator | | Join Date: Oct 2006 Location: Nashville, TN
Posts: 1,560
| | | re: Encrypt the password
Please use code tags. See "How to ask a question" in Posting Guidelines.
Are you having a problem with your code? Do you have a question?
-BV
Moderator
|  | Moderator | | Join Date: Oct 2006 Location: Nashville, TN
Posts: 1,560
| | | re: Encrypt the password
You can compare the hash value of the plain text to the stored hash value. Here's a simplified example using a dictionary: - import md5
-
-
dd = {'chiller': md5.new('abcdef123').digest(),
-
'hotpants': md5.new('zyx987').digest()}
-
-
def login(self):
-
uname=self.enText1.get()
-
pwd=self.enText2.get()
-
cpwd = self.enText3.get()
-
if pwd == cpwd and dd[uname] == md5.new(pwd).digest():
-
tkMessageBox.showinfo("Text", "Succesfully logged.")
-
self.master.destroy()
-
else:
-
tkMessageBox.showinfo("Text", "Invalid User Name and password.")
| | Newbie | | Join Date: Feb 2009
Posts: 8
| | | re: Encrypt the password
Hai,
Good Evening,
I'm doing a small application using python and MySQL. I want to encrypt the password to store in the database and also to decrypt the password while retriving the same password and also to redirect the next form.
While it stores in the database it should be in encrypted form and while accessing the password it should be decrypt it and checks the plain text with the encrypted text and it redirect to the next form.
This is the sample code: - #! /usr/bin/env python
-
from Tkinter import *
-
import tkMessageBox
-
import Tkinter
-
import time
-
-
-
curtime = ''
-
clock = Tkinter.Label(bg="tan")
-
clock.grid(row=22,column=0,columnspan=3,sticky=E)
-
-
def tick():
-
global curtime
-
newtime = time.strftime("TIME:"'%d/%m/%d %H:%M:%S')
-
if newtime != curtime:
-
curtime = newtime
-
clock.config(text=curtime)
-
clock.after(200, tick)
-
-
tick()
-
-
class GUIFramework(Frame):
-
"""This is the GUI"""
-
-
def __init__(self,master=None):
-
"""Initialize yourself"""
-
-
"""Initialise the base class"""
-
Frame.__init__(self,master)
-
-
"""Set the Window Title"""
-
self.master.title("LOGIN FORM")
-
self.master.config(bg="wheat")
-
"""Display the main window"
-
with a little bit of padding"""
-
self.grid(padx=10,pady=10)
-
self.CreateWidgets()
-
-
def CreateWidgets(self):
-
"""Create all the widgets that we need"""
-
self.config(bg="wheat")
-
self.lbText = Label(self,text="LOGIN DETAILS",bg="tan",relief="solid")
-
self.lbText.grid(row=0, column=0,sticky=NSEW,columnspan=50,pady=10)
-
-
"""Create the Text"""
-
self.lbText1 = Label(self,text="User Name:",bg="wheat",relief="groove",width=20)
-
self.lbText1.grid(row=1, column=0,sticky=W,columnspan=1)
-
-
"""Create the Entry, set it to be a bit wider"""
-
self.enText1 = Entry(self, width=25)
-
self.enText1.grid(row=1, column=1, columnspan=3,sticky=W)
-
-
self.lbText2 = Label(self, text="Password:",bg="wheat",relief="groove",width=20)
-
self.lbText2.grid(row=2, column=0,sticky=W)
-
-
self.enText2 = Entry(self,width=25,show="*")
-
self.enText2.grid(row=2, column=1, columnspan=3,sticky=W)
-
-
self.btnsubmit = Button(self, text="Login",command=self.login, bg='wheat',relief="groove",width=8)
-
self.btnsubmit.grid(row=3, column=0,sticky=E,pady=10)
-
-
def login(self):
-
uname=self.enText1.get()
-
pwd=self.enText2.get()
-
try:
-
import os
-
import MySQLdb
-
from hashlib import md5
-
import _mysql_exceptions as DB_EXC
-
cxn = MySQLdb.connect(user ='root')
-
cur = cxn.cursor()
-
pwd= md5(pwd)
-
no = cur.execute("select * from venlabs.users where uname=%s and pwd=%s",(uname,pwd))
-
cur.close()
-
cxn.commit()
-
cxn.close()
-
if (no != 0):
-
tkMessageBox.showinfo("Text", "succesfully logged." )
-
self.master.forward("/invoice1.py")
-
else:
-
tkMessageBox.showinfo("Text", "Invalid User Name and password.")
-
except ImportError , e:
-
return None
-
-
if __name__ == "__main__":
-
guiFrame = GUIFramework()
-
guiFrame.mainloop()
Please help me in this case. I'm struggling from last one month.
Thanks in advance for helping me.
Warm Regards,
Srinivas.
*** Moderator Note ***
This post was moved into an existing thread because it was a double post.
*** Moderator Note ***
| | Newbie | | Join Date: Feb 2009
Posts: 8
| | | re: Encrypt the password
Good Evening,
I'm doing a small application using python and mysql. I have encrypted the password using md5. but it is one way process. but I want to encrypt the password before storing into the database and while retriving the values it should be checked the plain text with the encrypted text.
Please help me.
Thanks in advance.
Warm Regards,
Srinivas
|  | Moderator | | Join Date: Oct 2006 Location: Nashville, TN
Posts: 1,560
| | | re: Encrypt the password Quote:
Originally Posted by cnivas Good Evening,
I'm doing a small application using python and mysql. I have encrypted the password using md5. but it is one way process. but I want to encrypt the password before storing into the database and while retriving the values it should be checked the plain text with the encrypted text.
Please help me.
Thanks in advance.
Warm Regards,
Srinivas Please see post #3 of this thread. Does this information help at all?
-BV
|  | Familiar Sight | | Join Date: Mar 2008 Location: Belgium
Posts: 136
| | | re: Encrypt the password
from a security point of view I would suggest SHA1 to hash passwords.
If you want to decrypt the password I would suggest using triple DES, but as you want to decrypt the password you need to store a key somewhere, which everybody could find. Again from a security point of view this is not the best thing to do :)
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,223 network members.
|