Pythoncard mental block

Steven D'Aprano steve at
Sat Oct 8 04:06:49 CEST 2005

On Fri, 07 Oct 2005 10:25:24 -0700, jlocc wrote:

> Hi!!
> I am working on a school project and I decided to use PythonCard and
> wxPython for my GUI development. I need a password window that will
> block unwanted users from the system. I got the pop-up password
> question to work...

I haven't seen any replies to this, so even though I don't actually
use Pythoncard I'll take a wild shot in the dark.

>    def on_openBackground(self, event):
>         result = dialog.textEntryDialog(self,
>                                     'System',
>                                     'Please enter your password: ',
>                                     '')
> .....but I don't exactly remember how to check if the entered password
> is correct. Say I hard code the password to be 'hello', then how would I
> check if this was the input or if it wasn't???

Start with looking at result and seeing what is in it. If it is the input
string, then just say 

if result == 'hello':
    # do whatever you need to
    # put up a dialog saying 'Password does not match!'

But I'm guessing from the syntax that the dialog instance itself is stored
in result, so perhaps you need to look at some attribute of result:

if result.userInput == "hello":  # or something like that?

Lastly, I might not have used Pythoncard, but years ago I used to use
Hypercard rather a lot. In Hypercard, the password dialog would use a
one-way hash function to encrypt the typed response into a large integer
value. I assume Pythoncard is designed to do the same thing as Hypercard.

So, in rusty Hypercard syntax with Python-style comments:

# retrieve the numeric value of the password
put field "hidden password" into userpassword
# put up a dialog asking the user to enter a password
ask password "Please enter your password:"
if the result is "" then:
    # the user clicked Cancel, so just abort or go away or something
    go home
else if the result is userpassword:
    # we have a match!
    go to card "Secret card"
    # password doesn't match
    go to card "Password failure"

Hope this is of some help to you, and I haven't led you too far astray.


More information about the Python-list mailing list