473,473 Members | 3,363 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Encrypt the password

8 New Member
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.
Expand|Select|Wrap|Line Numbers
  1. #! /usr/bin/env python
  2. from Tkinter import *
  3. import tkMessageBox
  4. import Tkinter
  5. import time
  6.  
  7.  
  8.  
  9. curtime = ''
  10. clock = Tkinter.Label(bg="tan")
  11. clock.grid(row=22,column=0,columnspan=3,sticky=E)
  12.  
  13. def tick():
  14.     global curtime
  15.     newtime = time.strftime("TIME:"'%d/%m/%d %H:%M:%S')
  16.     if newtime != curtime:
  17.         curtime = newtime
  18.         clock.config(text=curtime)
  19.     clock.after(200, tick)
  20.  
  21. tick()
  22.  
  23. class GUIFramework(Frame):
  24.     """This is the GUI"""
  25.  
  26.     def __init__(self,master=None):
  27.         """Initialize yourself"""
  28.  
  29.         """Initialise the base class"""
  30.         Frame.__init__(self,master)
  31.  
  32.         """Set the Window Title"""
  33.         self.master.title("LOGIN FORM")
  34.         self.master.config(bg="wheat")
  35.         """Display the main window"
  36.         with a little bit of padding"""
  37.         self.grid(padx=10,pady=10)
  38.         self.CreateWidgets()
  39.  
  40.     def CreateWidgets(self):
  41.         """Create all the widgets that we need"""
  42.         self.config(bg="wheat")
  43.         self.lbText = Label(self,text="LOGIN DETAILS",bg="tan",relief="solid")
  44.         self.lbText.grid(row=0, column=0,sticky=NSEW,columnspan=50,pady=10)
  45.  
  46.         """Create the Text"""
  47.         self.lbText1 = Label(self,text="User Name:",bg="wheat",relief="groove",width=20)
  48.         self.lbText1.grid(row=1, column=0,sticky=W,columnspan=1)
  49.  
  50.         """Create the Entry, set it to be a bit wider"""
  51.         self.enText1 = Entry(self, width=25)
  52.         self.enText1.grid(row=1, column=1, columnspan=3,sticky=W)
  53.  
  54.         self.lbText2 = Label(self, text="Password:",bg="wheat",relief="groove",width=20)
  55.         self.lbText2.grid(row=2, column=0,sticky=W)
  56.  
  57.         self.enText2 = Entry(self,width=25,show="*")
  58.         self.enText2.grid(row=2, column=1, columnspan=3,sticky=W)
  59.  
  60.         self.lbText3 = Label(self, text="Confirm Password:",bg="wheat",relief="groove",width=20)
  61.         self.lbText3.grid(row=3, column=0,sticky=W)
  62.  
  63.         self.enText3 = Entry(self,width=25,show="*")
  64.         self.enText3.grid(row=3, column=1, columnspan=3,sticky=W)
  65.  
  66.         self.btnsubmit = Button(self, text="Login",command=self.login, bg='wheat',relief="groove",width=8)
  67.         self.btnsubmit.grid(row=4, column=0,sticky=E,pady=10)
  68.  
  69.     def login(self):
  70.         uname=self.enText1.get()
  71.         pwd=self.enText2.get()
  72.         cpwd = self.enText3.get()
  73.         try:
  74.             import os
  75.             import MySQLdb
  76.             import _mysql_exceptions as DB_EXC
  77.             from hashlib import md5
  78.             cxn = MySQLdb.connect(user ='root')
  79.             cur = cxn.cursor()
  80.             no = cur.execute("insert into abc.users values (%s,%s)", (uname,pwd))  # here abc is the database and users is the table name
  81.             new = md5
  82.             st = cur.execute("update abc.users set pwd=MD5(pwd) where uname=%s", (uname))
  83.             cur.close()
  84.             cxn.commit()
  85.             cxn.close()
  86.             if (no != 0):
  87.                 tkMessageBox.showinfo("Text", "succesfully logged." )
  88.             else:
  89.                 tkMessageBox.showinfo("Text", "Invalid User Name and password.")
  90.         except ImportError , e:
  91.              return None
  92.  
  93. if __name__ == "__main__":
  94.     guiFrame = GUIFramework()
  95.     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
Apr 18 '09 #1
6 7008
bvdet
2,851 Recognized Expert Moderator Specialist
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
Apr 19 '09 #2
bvdet
2,851 Recognized Expert Moderator Specialist
You can compare the hash value of the plain text to the stored hash value. Here's a simplified example using a dictionary:
Expand|Select|Wrap|Line Numbers
  1. import md5
  2.  
  3. dd = {'chiller': md5.new('abcdef123').digest(),
  4.       'hotpants': md5.new('zyx987').digest()}
  5.  
  6.     def login(self):
  7.         uname=self.enText1.get()
  8.         pwd=self.enText2.get()
  9.         cpwd = self.enText3.get()
  10.         if pwd == cpwd and dd[uname] == md5.new(pwd).digest():
  11.             tkMessageBox.showinfo("Text", "Succesfully logged.")
  12.             self.master.destroy()
  13.         else:
  14.             tkMessageBox.showinfo("Text", "Invalid User Name and password.")
Apr 19 '09 #3
cnivas
8 New Member
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:
Expand|Select|Wrap|Line Numbers
  1. #! /usr/bin/env python
  2. from Tkinter import *
  3. import tkMessageBox
  4. import Tkinter
  5. import time
  6.  
  7.  
  8. curtime = ''
  9. clock = Tkinter.Label(bg="tan")
  10. clock.grid(row=22,column=0,columnspan=3,sticky=E)
  11.  
  12. def tick():
  13.     global curtime
  14.     newtime = time.strftime("TIME:"'%d/%m/%d %H:%M:%S')
  15.     if newtime != curtime:
  16.         curtime = newtime
  17.         clock.config(text=curtime)
  18.     clock.after(200, tick)
  19.  
  20. tick()
  21.  
  22. class GUIFramework(Frame):
  23.     """This is the GUI"""
  24.  
  25.     def __init__(self,master=None):
  26.         """Initialize yourself"""
  27.  
  28.         """Initialise the base class"""
  29.         Frame.__init__(self,master)
  30.  
  31.         """Set the Window Title"""
  32.         self.master.title("LOGIN FORM")
  33.         self.master.config(bg="wheat")
  34.         """Display the main window"
  35.         with a little bit of padding"""
  36.         self.grid(padx=10,pady=10)
  37.         self.CreateWidgets()
  38.  
  39.     def CreateWidgets(self):
  40.         """Create all the widgets that we need"""
  41.         self.config(bg="wheat")
  42.         self.lbText = Label(self,text="LOGIN DETAILS",bg="tan",relief="solid")
  43.         self.lbText.grid(row=0, column=0,sticky=NSEW,columnspan=50,pady=10)
  44.  
  45.         """Create the Text"""
  46.         self.lbText1 = Label(self,text="User Name:",bg="wheat",relief="groove",width=20)
  47.         self.lbText1.grid(row=1, column=0,sticky=W,columnspan=1)
  48.  
  49.         """Create the Entry, set it to be a bit wider"""
  50.         self.enText1 = Entry(self, width=25)
  51.         self.enText1.grid(row=1, column=1, columnspan=3,sticky=W)
  52.  
  53.         self.lbText2 = Label(self, text="Password:",bg="wheat",relief="groove",width=20)
  54.         self.lbText2.grid(row=2, column=0,sticky=W)
  55.  
  56.         self.enText2 = Entry(self,width=25,show="*")
  57.         self.enText2.grid(row=2, column=1, columnspan=3,sticky=W)
  58.  
  59.         self.btnsubmit = Button(self, text="Login",command=self.login, bg='wheat',relief="groove",width=8)
  60.         self.btnsubmit.grid(row=3, column=0,sticky=E,pady=10)
  61.  
  62.     def login(self):
  63.         uname=self.enText1.get()
  64.         pwd=self.enText2.get()
  65.         try:
  66.             import os
  67.             import MySQLdb
  68.             from hashlib import md5
  69.             import _mysql_exceptions as DB_EXC
  70.             cxn = MySQLdb.connect(user ='root')
  71.             cur = cxn.cursor()
  72.             pwd= md5(pwd) 
  73.             no = cur.execute("select * from venlabs.users where uname=%s and pwd=%s",(uname,pwd))
  74.             cur.close()
  75.             cxn.commit()
  76.             cxn.close()
  77.             if (no != 0):
  78.                 tkMessageBox.showinfo("Text", "succesfully logged." )
  79.                 self.master.forward("/invoice1.py")
  80.             else:
  81.                 tkMessageBox.showinfo("Text", "Invalid User Name and password.")
  82.         except ImportError , e:
  83.              return None
  84.  
  85. if __name__ == "__main__":
  86.     guiFrame = GUIFramework()
  87.     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 ***
Apr 20 '09 #4
cnivas
8 New Member
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
Apr 21 '09 #5
bvdet
2,851 Recognized Expert Moderator Specialist
@cnivas
Please see post #3 of this thread. Does this information help at all?

-BV
Apr 21 '09 #6
micmast
144 New Member
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 :)
Apr 22 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: CLEAR-RCIC | last post by:
Hello All: I want to encrypt a username/password inside a config file that will be read and decrypted by a .dll. I have discovered many ways to do this looking at Google but was wondering if...
3
by: f_salazar | last post by:
Im not goo writing in english, so here I go ! Public Shared Function Encriptar(ByVal cleanString As String) As String Dim clearBytes As () clearBytes = New...
3
by: Jason Williard | last post by:
How would I encrypt a string using MD5? -- Thank You, Jason Williard
2
by: Daniel | last post by:
Hi All, Does anyone know how to encrypt the password before store in the sql database? In addition, decrypt the password from database before comparison. The purpose to do it because to hide the...
1
by: Feng | last post by:
Hi, In my project I have a need for encrypting the password portion (only password, not the whole file) of my database connection string, so the password doesn't show as plain text. So, basicly,...
1
by: ghjk | last post by:
I m developing web base system. I want to add the facility to create users. And could you please tell me how to encrypt their password in mysql database?
1
by: agarwalsunitadhn | last post by:
hi.... I want to encrypt my password so that no one can view it and in the case of transfer also there is no way to access this one. In short i want to safely transfer the data through...
5
by: poolboi | last post by:
hi guys, i would like to ask thing son encryption of data presently i'm setting up a mysql database to store usernames and password for authentication is there ways i can encrypt the column...
4
by: Gilles Ganault | last post by:
Hello I'd like to encrypt a customer's organization name to use this as their password to launch our application, and decrypt it within our VB5 application. We will then use this information...
2
by: ghjk | last post by:
I have to develop a web application using JSP. I'm new to JSP. Could some one tell me how to encrypt password using JSP. I know php.
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.