8 from Crypto.Cipher import AES
9 from binascii import b2a_hex, a2b_hex
11 import simplejson as json
12 from gi.repository import Notify
15 if locale.getdefaultlocale()[0] == 'zh_CN':
16 gettext.install('messages', './locale', unicode=False)
17 gettext.translation('messages', './locale', languages=['cn']).install(True)
19 def __init__(self, key):
21 self.mode = AES.MODE_CBC
22 def decrypt(self, text):
23 cryptor = AES.new(self.key, self.mode, self.key)
24 plain_text = cryptor.decrypt(a2b_hex(text))
25 return plain_text.rstrip('\0')
26 class LoginFrame(wx.Frame):
27 def __init__(self, parent, id, title, size):
28 wx.Frame.__init__(self, parent, id, title)
31 self.passWordLabel = wx.StaticText(self, label = _("UserName"), pos = (30, 50), size = (120, 25))
32 self.userNameLabel = wx.StaticText(self, label = _("Password"), pos = (30, 100), size = (120, 25))
33 self.userName = wx.TextCtrl(self, pos = (100, 47), size = (150, 25))
34 self.passWord= wx.TextCtrl(self, pos = (100, 97), size = (150, 25),style=wx.TE_PASSWORD)
35 self.loginButton = wx.Button(self, label = _('Login'), pos = (80, 145), size = (130, 30))
36 self.loginButton.Bind(wx.EVT_BUTTON,self.login)
39 if not self.userName.GetValue():
40 wx.MessageBox(_('Please enter the username'), _('Error'),
41 wx.OK | wx.ICON_ERROR)
42 elif not self.passWord.GetValue():
43 wx.MessageBox(_('Please enter the password'), _('Error'),
44 wx.OK | wx.ICON_ERROR)
47 db=MySQLdb.connect(host="sql6.freesqldatabase.com",user="sql685198",passwd="jH8*bX3*",db="sql685198",port=3306 )
49 sql = "SELECT uncompress(password) FROM user WHERE name = '%s' LIMIT 1"%(self.userName.GetValue())
51 results = cursor.fetchall()
56 wx.MessageBox(_('Unable to fecth data,Please check your username'), _('Try it again'),
57 wx.OK | wx.ICON_ERROR)
58 except MySQLdb.Error, e:
59 wx.MessageBox('Error %d: %s' % (e.args[0], e.args[1]), _('Try it again'),
60 wx.OK | wx.ICON_ERROR)
61 passwd0 = pc.decrypt(password)
62 if self.passWord.GetValue()==passwd0:
64 cursor.execute("SELECT uncompress(Data) FROM friendlist WHERE name = '%s' LIMIT 1"%(self.userName.GetValue()))
65 data = json.loads(cursor.fetchone()[0])
70 wx.MessageBox('Error %d: %s' % (e.args[0], e.args[1]), 'Try it again',
71 wx.OK | wx.ICON_ERROR)
72 #urllib2.urlopen('http://chat-tyl.coding.io/user_log?info=User___'+self.userName.GetValue()+'___Login')
73 Notify.init ("Chat-TYL")
74 bubble_notify = Notify.Notification.new (_("Information"),_("Login Successful"),"file://" + os.path.abspath(os.path.curdir) + "/Chat-TYL.ico")
77 frame = FriendList.MyFrame(None, id=-1, title=_("Friend List"),user=data,un=self.userName.GetValue())
80 wx.MessageBox(_('Your Password is wrong'), _('Try it again'),
81 wx.OK | wx.ICON_ERROR)
82 if __name__ == '__main__':
83 pc = prpcrypt('keyskeyskeyskeys')
85 LoginFrame(None, -1, title = _("Login"), size = (280, 200))