Ejemplo n.º 1
0
    def _getMail(self):
        if self.ssl:
            cn = imaplib.IMAP4_SSL(self.server, self.port)
        else:
            cn = imaplib.IMAP4(self.server, self.port)

        if self._PASSWORDS.has_key((self.server, self.user, self.port)):
            pwd = self._PASSWORDS[(self.server, self.user, self.port)]
        else:
            pwd = wx.GetPasswordFromUser(_('Please enter password for user %(user)s on %(server)s:%(port)d') % \
                                         dict(user=self.user, server=self.server, port=self.port))
            if pwd == '':
                raise ValueError('User canceled')

        while True:
            try:
                response, params = cn.login(self.user, pwd)
            except cn.error, e:
                response = 'KO'
                errmsg, = e.args

            if response == 'OK':
                break

            pwd = wx.GetPasswordFromUser(_('Login failed (%s). Please try again.') % errmsg)
            if pwd == '':
                raise ValueError('User canceled')
Ejemplo n.º 2
0
	def __get_password(self, msg_title):
		while True:
			data_pwd = wx.GetPasswordFromUser (
				message = _(
					'Enter passphrase to protect the data with.\n'
					'\n'
					'(minimum length: 5, trailing blanks will be stripped)'
				),
				caption = msg_title
			)
			# minimal weakness check
			data_pwd = data_pwd.rstrip()
			if len(data_pwd) > 4:
				break
			retry = gmGuiHelpers.gm_show_question (
				title = msg_title,
				question = _(
					'Insufficient passphrase.\n'
					'\n'
					'(minimum length: 5, trailing blanks will be stripped)\n'
					'\n'
					'Enter another passphrase ?'
				)
			)
			if not retry:
				# user changed her mind
				return None
		# confidentiality
		gmLog2.add_word2hide(data_pwd)
		# reget password
		while True:
			data_pwd4comparison = wx.GetPasswordFromUser (
				message = _(
					'Once more enter passphrase to protect the data with.\n'
					'\n'
					'(this will protect you from typos)\n'
					'\n'
					'Abort by leaving empty.'
				),
				caption = msg_title
			)
			data_pwd4comparison = data_pwd4comparison.rstrip()
			if data_pwd4comparison == '':
				# user changed her mind ...
				return None
			if data_pwd == data_pwd4comparison:
				break
			gmGuiHelpers.gm_show_error (
				error = _(
					'Passphrases do not match.\n'
					'\n'
					'Retry, or abort with an empty passphrase.'
				),
				title = msg_title
			)
		return data_pwd
Ejemplo n.º 3
0
 def try_decrypt_document(self, document):
     if not document.is_encrypted():
         return True
     password = wx.GetPasswordFromUser(
         # Translators: the content of a dialog asking the user
         # for the password to decrypt the current e-book
         _("This document is encrypted with a password.\n"
           "You need to provide the password in order to access its content.\n"
           "Please provide the password and press enter."),
         # Translators: the title of a dialog asking the user to enter a password to decrypt the e-book
         _("Enter Password"),
         parent=self,
     )
     if not password:
         return False
     result = document.decrypt(password)
     if not result:
         self.notify_user(
             # Translators: title of a message telling the user that they entered an incorrect
             # password for opening the book
             _("Incorrect Password"),
             # Translators: content of a message telling the user that they entered an incorrect
             # password for opening the book
             _("The password you provided is incorrect.\n"
               "Please try again with the correct password."),
             icon=wx.ICON_ERROR,
         )
         return self.try_decrypt_document(document)
     return result
Ejemplo n.º 4
0
    def OnSelectLogcatClicked(self, event):
        # pass
        pw = wx.GetPasswordFromUser('请输入管理密码',
                                    caption="查询",
                                    default_value="",
                                    parent=self.bmp)
        if pw == '':
            print('取消查询')
        elif pw != PASSWORD:
            wx.MessageBox(message='密码错误,退出查询', caption='警告')
        else:
            self.loadDataBase(2)
            set_logcat_id = list(set(self.logcat_id))
            set_logcat_id = [str(x) for x in set_logcat_id]
            set_logcat_unit = list(set(self.logcat_unit))

            self.logcat_datetime_in = [
                self.logcat_datetime_in[x]
                [0:self.logcat_datetime_in[x].index(' ')]
                for x in range(len(self.logcat_datetime_in))
            ]
            set_logcat_datetime_in = list(set(self.logcat_datetime_in))

            self.frm = SelectLogcat(set_logcat_id,
                                    set_logcat_unit,
                                    set_logcat_datetime_in,
                                    None,
                                    title='查询',
                                    size=(680, 400))
            # self.frm.SetSizer()
            self.frm.Show(True)
Ejemplo n.º 5
0
 def onclic(self, evt):
     msg = 'Inserire la password per procedere:'
     cpt = 'Password richiesta.'
     if check_psw(wx.GetPasswordFromUser(msg, cpt)):
         evt.Skip()
     else:
         wx.MessageBox('Password errata!', 'Password errata',
                       wx.ICON_ERROR | wx.OK)
Ejemplo n.º 6
0
 def on_leftup(self, evt):
     msg = 'Inserire la password per procedere:'
     cpt = 'Password richiesta.'
     if check_psw(wx.GetPasswordFromUser(msg, cpt)):
         wx.PostEvent(self.GetEventHandler(),
                      wx.PyCommandEvent(wx.EVT_BUTTON.typeId, self.GetId()))
     else:
         wx.MessageBox('Password errata!', 'Password errata',
                       wx.ICON_ERROR | wx.OK)
Ejemplo n.º 7
0
def GetPassword(domain, username, reset=False):
    global _PASSWORDCACHE

    try:
        from taskcoachlib.thirdparty.keyring import set_password, get_password
    except:
        # Keychain unavailable.
        if _PASSWORDCACHE is None:
            import StringIO, traceback
            bf = StringIO.StringIO()
            traceback.print_exc(file=bf)
            wx.MessageBox(
                _('There was a problem trying to find out your system\'s keychain.\nPlease file a bug report (see the Help menu) and attach a screenshot of this message.\nError was:\n\n%s'
                  ) % bf.getvalue(), _('Error'), wx.OK)
            _PASSWORDCACHE = dict()
        if (domain, username) in _PASSWORDCACHE and reset:
            del _PASSWORDCACHE[(domain, username)]
        if (domain, username) not in _PASSWORDCACHE:
            pwd = wx.GetPasswordFromUser(_('Please enter your password.'),
                                         domain)
            if not pwd:
                return None
            _PASSWORDCACHE[(domain, username)] = pwd
        return _PASSWORDCACHE[(domain, username)]

    if reset:
        set_password(domain.encode('UTF-8'), username.encode('UTF-8'), '')
    else:
        pwd = get_password(domain.encode('UTF-8'), username.encode('UTF-8'))
        if pwd:
            return pwd.decode('UTF-8')

    dlg = KeychainPasswordWidget(domain,
                                 username,
                                 None,
                                 wx.ID_ANY,
                                 _('Please enter your password'),
                                 style=wx.DEFAULT_DIALOG_STYLE
                                 | wx.STAY_ON_TOP)
    try:
        dlg.CentreOnScreen()
        if dlg.ShowModal() == wx.ID_OK:
            return dlg.password
    finally:
        dlg.Destroy()
Ejemplo n.º 8
0
def get_dbowner_connection(procedure=None,
                           dbo_password=None,
                           dbo_account='gm-dbo'):
    if procedure is None:
        procedure = _('<restricted procedure>')

    # 1) get password for gm-dbo
    if dbo_password is None:
        dbo_password = wx.GetPasswordFromUser(message=_("""
 [%s]

This is a restricted procedure. We need the
current password for the GNUmed database owner.

Please enter the current password for <%s>:""") % (procedure, dbo_account),
                                              caption=procedure)
        if dbo_password == '':
            return None

    gmLog2.add_word2hide(dbo_password)

    # 2) connect as gm-dbo
    login = gmPG2.get_default_login()
    dsn = gmPG2.make_psycopg2_dsn(database=login.database,
                                  host=login.host,
                                  port=login.port,
                                  user=dbo_account,
                                  password=dbo_password)
    try:
        conn = gmPG2.get_connection(dsn=dsn,
                                    readonly=False,
                                    verbose=True,
                                    pooled=False)
    except Exception:
        _log.exception('cannot connect')
        gmGuiHelpers.gm_show_error(
            aMessage=_('Cannot connect as the GNUmed database owner <%s>.') %
            dbo_account,
            aTitle=procedure)
        gmPG2.log_database_access(
            action='failed to connect as database owner for [%s]' % procedure)
        return None

    return conn
Ejemplo n.º 9
0
def _GetCachedPassword(domain, username, reset):
    global _PASSWORDCACHE

    if _PASSWORDCACHE is None:
        import StringIO, traceback
        bf = StringIO.StringIO()
        traceback.print_exc(file=bf)
        wx.MessageBox(
            _('There was a problem trying to find out your system\'s keychain.\nPlease file a bug report (see the Help menu) and attach a screenshot of this message.\nError was:\n\n%s'
              ) % bf.getvalue(), _('Error'), wx.OK)
        _PASSWORDCACHE = dict()
    if (domain, username) in _PASSWORDCACHE and reset:
        del _PASSWORDCACHE[(domain, username)]
    if (domain, username) not in _PASSWORDCACHE:
        pwd = wx.GetPasswordFromUser(_('Please enter your password.'), domain)
        if not pwd:
            return None
        _PASSWORDCACHE[(domain, username)] = pwd
    return _PASSWORDCACHE[(domain, username)]
Ejemplo n.º 10
0
 def decrypt_opened_document(self):
     pwd = wx.GetPasswordFromUser(
         # Translators: the content of a dialog asking the user
         # for the password to decrypt the current e-book
         _(
             "This document is encrypted, and you need a password to access its content.\nPlease enter the password billow and press enter."
         ),
         # Translators: the title of a dialog asking the user to enter a password to decrypt the e-book
         "Enter Password",
         parent=self,
     )
     res = self.reader.document.decrypt(pwd.GetValue())
     if not res:
         wx.MessageBox(
             # Translators: the content of a message
             _("The password you've entered is invalid.\nPlease try again."),
             # Translators: the title of an error message
             _("Invalid Password"),
             parent=self,
             style=wx.ICON_ERROR,
         )
         return self.decrypt_opened_document()
Ejemplo n.º 11
0
 def OnManageFaceClicked(self, event):
     pw = wx.GetPasswordFromUser('请输入管理密码',
                                 caption="删除",
                                 default_value="",
                                 parent=self.bmp)
     if pw == '':
         print('取消删除')
     elif pw != PASSWORD:
         wx.MessageBox(message='密码错误,退出删除', caption='警告')
     else:
         self.loadDataBase(1)
         delete_id = wx.GetTextFromUser(message='请输入删除学生的学号',
                                        caption='删除',
                                        parent=self.bmp,
                                        default_value='-1')
         delete_id = int(delete_id)
         # 取消修改
         if delete_id == -1:
             # self.infoText.AppendText(
             #     '[%s]' % getDateAndTime(hms=1) + '取消添加\r\n')
             print('取消删除')
         else:
             delete_flag = 0
             for i, j in enumerate(self.knew_id):
                 if j == delete_id:
                     dlg = wx.MessageDialog(None,
                                            '请确认删除的学生为:{}学院的{}学生吗?'.format(
                                                self.knew_unit[i],
                                                self.knew_name[i]),
                                            caption='确认',
                                            style=wx.YES_NO)
                     if dlg.ShowModal() == wx.ID_YES:
                         # 删除数据库
                         self.deleteRow(i)
                     delete_flag = 1
             if not delete_flag:
                 wx.MessageBox(message='查无此人', caption='警告')
Ejemplo n.º 12
0
def 组件_密码对话框(提示="", 标题="请输入密码", 默认文本="", 父窗口=None):
    "弹出一个文本对话框,输入的内容会被替换成圆点,适合密码等输入使用,确认后返回输入的内容,取消返回空文本"
    return wx.GetPasswordFromUser(message=提示,
                                  caption=标题,
                                  default_value=默认文本,
                                  parent=父窗口)
Ejemplo n.º 13
0
def change_gmdbowner_password():

    title = _('Changing GNUmed database owner password')

    dbo_account = wx.GetTextFromUser(
        message=_("Enter the account name of the GNUmed database owner:"),
        caption=title,
        default_value='')

    if dbo_account.strip() == '':
        return False

    dbo_conn = get_dbowner_connection(procedure=title, dbo_account=dbo_account)
    if dbo_conn is None:
        return False

    dbo_pwd_new_1 = wx.GetPasswordFromUser(
        message=_("Enter the NEW password for the GNUmed database owner:"),
        caption=title)
    if dbo_pwd_new_1.strip() == '':
        return False

    gmLog2.add_word2hide(dbo_pwd_new_1)

    dbo_pwd_new_2 = wx.GetPasswordFromUser(message=_(
        """Enter the NEW password for the GNUmed database owner, again.

(This will protect you from typos.)
		"""),
                                           caption=title)
    if dbo_pwd_new_2.strip() == '':
        return False

    if dbo_pwd_new_1 != dbo_pwd_new_2:
        return False

    # pwd2 == pwd1 at this point so no need to hide (again)
    """	On Mon, Mar 13, 2017 at 12:19:22PM -0400, Tom Lane wrote:
		> Date: Mon, 13 Mar 2017 12:19:22 -0400
		> From: Tom Lane <*****@*****.**>
		> To: Adrian Klaver <*****@*****.**>
		> cc: Schmid Andreas <*****@*****.**>,
		>  "'*****@*****.**'" <*****@*****.**>
		> Subject: Re: [GENERAL] createuser: How to specify a database to connect to
		> 
		> Adrian Klaver <*****@*****.**> writes:
		> > On 03/13/2017 08:52 AM, Tom Lane wrote:
		> >> If by "history" you're worried about the server-side statement log, this
		> >> is merest fantasy: the createuser program is not magic, it just constructs
		> >> and sends a CREATE USER command for you.  You'd actually be more secure
		> >> using psql, where (if you're superuser) you could shut off log_statement
		> >> for your session first.
		> 
		> > There is a difference though:
		> 
		> > psql> CREATE USER:
		> 
		> > postgres-2017-03-13 09:03:27.147 PDT-0LOG:  statement: create user 
		> > dummy_user with login password '1234';
		> 
		> Well, what you're supposed to do is
		> 
		> postgres=# create user dummy_user;
		> postgres=# \password dummy_user
		> Enter new password: 
		> Enter it again: 
		> postgres=# 
		> 
		> which will result in sending something like
		> 
		> ALTER USER dummy_user PASSWORD 'md5c5e9567bc40082671d02c654260e0e09'
		> 
		> You can additionally protect that by wrapping it into one transaction
		> (if you have a setup where the momentary existence of the role without a
		> password would be problematic) and/or shutting off logging beforehand.
	"""

    # this REALLY should be prefixed with md5 and the md5sum sent rather than the pwd
    cmd = """ALTER ROLE "%s" ENCRYPTED PASSWORD '%s';""" % (dbo_account,
                                                            dbo_pwd_new_2)
    gmPG2.run_rw_queries(link_obj=dbo_conn,
                         queries=[{
                             'cmd': cmd
                         }],
                         end_tx=True)

    return True
Ejemplo n.º 14
0
import wx


if __name__ == '__main__':
    app = wx.App()
    app.MainLoop()
    ret = wx.GetPasswordFromUser("Get password from user:"******"Get password function", "default")
    if ret == '':
        print('press cancel or input none')
    else:
        print('press ok, input string: %s' % ret)
Ejemplo n.º 15
0
 def OnChangeTimeClicked(self, event):
     # cur_hour = datetime.datetime.now().hour
     # print(cur_hour)
     # if cur_hour>=8 or cur_hour<6:
     #     wx.MessageBox(message='''您错过了今天的签到时间,请明天再来\n
     #     每天的签到时间是:6:00~7:59''', caption='警告')
     #     return
     # pass
     pw = wx.GetPasswordFromUser('请输入管理密码',
                                 caption="修改",
                                 default_value="",
                                 parent=self.bmp)
     if pw == '':
         print('取消修改')
     elif pw != PASSWORD:
         wx.MessageBox(message='密码错误,退出修改', caption='警告')
     else:
         # 输入修改时间,如果输入为空,则取消修改,如果输入格式错误,则重新修改
         flag = 1
         time_type = ['签到时间', '签退时间']
         index = -1
         while flag and index == -1:
             # 选择时间
             choice_time_type = wx.SingleChoiceDialog(
                 parent=self.bmp,
                 message='请选择您要修改的时间',
                 caption='修改',
                 choices=time_type,
             )
             if choice_time_type.ShowModal() == wx.ID_CANCEL:
                 print('取消修改')
                 flag = 0
                 break
             else:
                 index = choice_time_type.GetSelection()
                 # break
         # 输入时间
         # TODO 确认是否更新今日签到记录
         while flag and index != -1:
             change_time = wx.GetTextFromUser(
                 message='请输入修改的时间(格式HH:MM:SS)',
                 caption='修改{}'.format(time_type[index]),
                 default_value=self.puncard_time[index],
                 parent=self.bmp)
             if change_time.strip(
             ) == '' or change_time == self.puncard_time[index]:
                 self.infoText.AppendText('[{}]取消修改(上一次为:{})\r\n'.format(
                     getDateAndTime(hms=1), self.puncard_time[index]))
                 print('取消修改')
                 index = -1
                 break
             else:
                 try:
                     # 判断时间大小
                     changed = datetime.datetime.strptime(
                         change_time, '%H:%M:%S')
                     original = datetime.datetime.strptime(
                         self.puncard_time[1 - index], '%H:%M:%S')
                     if changed > original if index else changed < original:
                         self.puncard_time[index] = change_time
                         np.save(conf.data_path / 'time.npy',
                                 self.puncard_time)
                         self.infoText.AppendText('[{}]{}已修改:{}\r\n'.format(
                             getDateAndTime(hms=1), time_type[index],
                             self.puncard_time[index]))
                         print('修改成功%s' % self.puncard_time[index])
                         index = -1
                         break
                     else:
                         print('修改错误:签到时间需早于签退时间')
                         wx.MessageBox(message='签到时间需早于签退时间,请重新输入',
                                       caption='警告')
                 except ValueError:
                     print('格式错误(格式为HH:MM:SS)')
                     wx.MessageBox(message='格式错误(格式为HH:MM:SS)',
                                   caption='警告')
Ejemplo n.º 16
0
 def __init__(self):
     password=wx.GetPasswordFromUser('请输入日记本启动密码','日记本已加密')
     if (not  password) or (not self.isKeyTrue(password)):
         wx.MessageBox('打开日记本出错了吧!','出错了吧,嘻嘻')
         sys.exit()
     diaryFrame=DiaryFrame()
Ejemplo n.º 17
0
# -*- coding: utf-8 -*-
# CRISTIAN ECHEVERRÍA RABÍ
# Archivo      : AboutDlgTest
# Fecha        : 29-08-2006 11:06:56

import wx

app = wx.PySimpleApp(False)  # True para capturar stderr y stdout

clave = wx.GetPasswordFromUser("Ingrese clave")

if clave == "sofita":
    frame = wx.Frame(parent=None, title='Bare')
    frame.Center()
    frame.Show()
else:
    wx.MessageBox("Clave incorrecta", "Error de acceso")

print wx.GetUserId()
app.MainLoop()
Ejemplo n.º 18
0
#! /usr/bin/env python 
# coding:utf-8

import wx

if __name__ == "__main__":
    app = wx.PySimpleApp()
    app.MainLoop()

    dialog = wx.TextEntryDialog(None,
        "What kind of text would you like to enter?","Text Entry","Default Value",style = wx.OK | wx.CANCEL | wx.TE_PASSWORD | wx.TE_CENTER)
    retCode = dialog.ShowModal()
    if retCode == wx.ID_OK:
        print "You entered:%s" % dialog.GetValue()
    elif retCode == wx.ID_CANCEL:
        print "you cancel the option."

    dialog.Destroy()
    
    # 方法二 三类函数
    message = "Hey,What I can do for you?"
    ret = []
    ret.append(wx.GetTextFromUser(message))
    ret.append(wx.GetPasswordFromUser(message))
    ret.append(wx.GetNumberFromUser(message,"-100 to 100","Input A Number",10,-100,100))
    print(ret)