[wxPython] Password Dialog Box

Is there a dialog box to collect a password? I am
writing an app and would like to save the username,
ip, port, and all other required info to hit a
process, but would like to prompt the user for a
password every time they actually want to connect
to the backend. I would like a dialog that comes up
prompting for the password, but not displaying it
as they type it in.

Thanks for your help

Greg Lindstrom

Greg, if you have not already implemented something else, here is what I
came up with for a project that I am working on:

from wxPython.wx import *
import sha

class LoginDialog(wxDialog):
    def __init__(self, parent, id=-1, title="Login",
                 pos=wxDefaultPosition,
                 size=wxSize(250, 150)):
        wxDialog.__init__(self, parent, id, title, pos, size)
        wxStaticText(self, -1, 'Please type your user name and password.',
                     wxPoint(15, 5))
        wxStaticText(self, -1, 'User name: ', wxPoint(20, 30))
        wxStaticText(self, -1, 'Password: ', wxPoint(20, 55))
        self.nameBox = wxTextCtrl(self, -1, '', wxPoint(80,30),
                                  wxSize(120, -1))
        self.passwordBox = wxTextCtrl(self, -1, '', wxPoint(80,55),
                                 wxSize(120, -1), style=wxTE_PASSWORD)
        wxButton(self, wxID_OK, ' OK ', wxPoint(35, 90),
                 wxDefaultSize).SetDefault()
        wxButton(self, wxID_CANCEL, ' Cancel ', wxPoint(135, 90),
                 wxDefaultSize)

    def GetUser(self):
        val = self.ShowModal()
        if val == wxID_OK:
            username = self.nameBox.GetValue()
            h = sha.new(self.passwordBox.GetValue())
            password = h.hexdigest()
            return [username, password]
        else:
            return None

class testLogin(wxApp):
    def OnInit(self):
        main = wxFrame(None, -1, 'Main Frame')
        main.Show(true)
        self.SetTopWindow(main)
        login = LoginDialog(main)
        user = login.GetUser()
        print user
        return true

app = testLogin(0)
app.MainLoop()

To Robin and the rest of the list:

1. I used the sha module to encrypt the password, as I plan to keep the
password list in encrypted format. I would have used crypt(), but I am
deploying on win32. [Doesn't crypt() require a Unix platform?] Is there a
better algorithm to use for this purpose?

2. Is this login dialog of general enough interest to warrant my writing it
up for the wxPyWiki cookbook? I've never contributed to a Wiki before, but
I'd be happy to give it a whirl if anyone thinks it would be worthwhile. (If
not, I won't be offended. :slight_smile:

Donnal Walter
Arkansas Children's Hospital
walterdonnalc at uams.edu

It's self-contained and to a single point - I thought that's exactly what the
wiki was meant to hold. It's just the sort of thing I was looking for
early on.

···

On July 8, 2001 04:33 am, WalterDonnalC@uams.edu wrote:

2. Is this login dialog of general enough interest to warrant my writing it
up for the wxPyWiki cookbook? I've never contributed to a Wiki before, but
I'd be happy to give it a whirl if anyone thinks it would be worthwhile.
(If not, I won't be offended. :slight_smile:

Donnal Walter
Arkansas Children's Hospital

--
Regards, Paul Evans

2. Is this login dialog of general enough interest to warrant my writing

it

up for the wxPyWiki cookbook? I've never contributed to a Wiki before, but
I'd be happy to give it a whirl if anyone thinks it would be worthwhile.

(If

not, I won't be offended. :slight_smile:

Yes, it would make a good cookbook entry.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!