Pythoncard mental block

J

jlocc

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...

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???

Sorry, I've got a mental block....I'm using the latest
everything....thankssss!!
 
S

Steven D'Aprano

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
else:
# 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"
else:
# 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top