Beispiel #1
0
def GetPassword(domain, username, reset=False):
    try:
        from taskcoachlib.thirdparty.keyring import set_password, get_password
    except:
        # Keychain unavailable.
        return _GetCachedPassword(domain, username, reset)

    try:
        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')
    except ImportError:
        # Bug seen on Ubuntu 13.10: secretstorage cannot import ._gi
        return _GetCachedPassword(domain, username, reset)

    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()
Beispiel #2
0
def GetPassword(domain, username, reset=False):
    try:
        from taskcoachlib.thirdparty.keyring import set_password, get_password
    except:
        # Keychain unavailable.
        return _GetCachedPassword(domain, username, reset)

    try:
        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')
    except ImportError:
        # Bug seen on Ubuntu 13.10: secretstorage cannot import ._gi
        return _GetCachedPassword(domain, username, reset)

    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()
Beispiel #3
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()
Beispiel #4
0
    def __init__(self, domain, username, *args, **kwargs):
        super(KeychainPasswordWidget, self).__init__(*args, **kwargs)

        self.domain = domain.encode('UTF-8')
        self.username = username.encode('UTF-8')

        pnl = wx.Panel(self, wx.ID_ANY)
        hsz = wx.BoxSizer(wx.HORIZONTAL)
        hsz.Add(wx.StaticText(pnl, wx.ID_ANY, _('Password:'******'').decode('UTF-8')
        self.passwordField = wx.TextCtrl(pnl,
                                         wx.ID_ANY,
                                         self.password,
                                         style=wx.TE_PASSWORD)
        hsz.Add(self.passwordField, 1, wx.ALL, 3)

        vsz = wx.BoxSizer(wx.VERTICAL)
        vsz.Add(hsz, 0, wx.ALL | wx.EXPAND, 3)
        self.keepInKeychain = wx.CheckBox(pnl, wx.ID_ANY,
                                          _('Store in keychain'))
        self.keepInKeychain.SetValue(bool(password))
        vsz.Add(self.keepInKeychain, 0, wx.ALL | wx.EXPAND, 3)

        hsz = wx.BoxSizer(wx.HORIZONTAL)
        btnOK = wx.Button(pnl, wx.ID_ANY, _('OK'))
        hsz.Add(btnOK, 0, wx.ALL, 3)
        btnCancel = wx.Button(pnl, wx.ID_ANY, _('Cancel'))
        hsz.Add(btnCancel, 0, wx.ALL, 3)
        vsz.Add(hsz, 0, wx.ALL | wx.ALIGN_CENTRE, 3)

        pnl.SetSizer(vsz)

        sz = wx.BoxSizer(wx.HORIZONTAL)
        sz.Add(pnl, 1, wx.EXPAND | wx.ALL, 3)
        self.SetSizer(sz)
        self.Fit()

        wx.EVT_BUTTON(btnOK, wx.ID_ANY, self.OnOK)
        wx.EVT_BUTTON(btnCancel, wx.ID_ANY, self.OnCancel)

        self.SetDefaultItem(btnOK)
        wx.CallAfter(self.RequestUserAttention)
Beispiel #5
0
    def __init__(self, domain, username, *args, **kwargs):
        super(KeychainPasswordWidget, self).__init__(*args, **kwargs)

        self.domain = domain.encode('UTF-8')
        self.username = username.encode('UTF-8')

        pnl = wx.Panel(self, wx.ID_ANY)
        hsz = wx.BoxSizer(wx.HORIZONTAL)
        hsz.Add(wx.StaticText(pnl, wx.ID_ANY, _('Password:'******'').decode('UTF-8')
        self.passwordField = wx.TextCtrl(pnl, wx.ID_ANY, self.password, style=wx.TE_PASSWORD)
        hsz.Add(self.passwordField, 1, wx.ALL, 3)

        vsz = wx.BoxSizer(wx.VERTICAL)
        vsz.Add(hsz, 0, wx.ALL|wx.EXPAND, 3)
        self.keepInKeychain = wx.CheckBox(pnl, wx.ID_ANY, _('Store in keychain'))
        self.keepInKeychain.SetValue(bool(password))
        vsz.Add(self.keepInKeychain, 0, wx.ALL|wx.EXPAND, 3)

        hsz = wx.BoxSizer(wx.HORIZONTAL)
        btnOK = wx.Button(pnl, wx.ID_ANY, _('OK'))
        hsz.Add(btnOK, 0, wx.ALL, 3)
        btnCancel = wx.Button(pnl, wx.ID_ANY, _('Cancel'))
        hsz.Add(btnCancel, 0, wx.ALL, 3)
        vsz.Add(hsz, 0, wx.ALL|wx.ALIGN_CENTRE, 3)

        pnl.SetSizer(vsz)

        sz = wx.BoxSizer(wx.HORIZONTAL)
        sz.Add(pnl, 1, wx.EXPAND|wx.ALL, 3)
        self.SetSizer(sz)
        self.Fit()

        wx.EVT_BUTTON(btnOK, wx.ID_ANY, self.OnOK)
        wx.EVT_BUTTON(btnCancel, wx.ID_ANY, self.OnCancel)

        self.SetDefaultItem(btnOK)
        wx.CallAfter(self.RequestUserAttention)
Beispiel #6
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'))
    try:
        dlg.CentreOnScreen()
        if dlg.ShowModal() == wx.ID_OK:
            return dlg.password
    finally:
        dlg.Destroy()