[Tutor] Pretty and invisible
kromag@nsacom.net
kromag@nsacom.net
Fri, 26 Oct 2001 15:39:11 -0700 (PDT)
I would like to do two things with the following script:
First, I believe it could be made much simpler and prettier: May I have
suggestions?
I found an example of a phone book script in "Learning Python" that is
similar, I will begin there, but I get easily lost in inheritance (judging
from my last post, I would get lost on the way to the bathroom....) :-)
Second, I would like to either not echo or obscure the password raw_input().
I have looked through Learing Python and around the web for examples: I am
probably missing it!
**ALERT**ALERT**ALERT**ALERT**ALERT**ALERT**
Mail from this account is sent from a webmail program called TWIG.
TWIG will strip the leading /'s from open('//tmp//filename') and the like.
Thanks!
_________________login.py__________________
import cPickle
import string
import time
import sys
import os
'''login checks a pickled dictionary for usernames/passwords,
creates new u/p's and rejects mistyped passwords'''
#open password file, grab the dictionary of usernames and passwords, then
close it.
passwd=open('\tmp\passwd','r')
passlist=cPickle.load(passwd)
passwd.close()
#untrused username password combination
uname=raw_input('Enter Player Name: ')
password=raw_input('Enter Password: ')
untrusted={uname: password}
#check and see if the existing passlist has the username
check=passlist.has_key(uname)
#if there is no existing key in passlist that matches uname, add it and a
password.
if check==0:
print 'Name not found. Adding.'
password=raw_input('Enter new Password for '+uname+': ')
passlist[uname]=password
passwd=open('\tmp\passwd','w')
cPickle.dump(passlist, passwd)
passwd.close()
print 'user and password added'
os.system('\windows\command\edit.com ' +uname)
sys.exit()
#if the values for the passlist key match the value for untrusted key, start
app.
elif passlist[uname] == untrusted[uname]:
print 'user + pass ok '
os.system('\windows\command\edit.com ' +uname)
sys.exit()
#if the values for the passlist key do not match the value for the untrusted
key, kill script
elif passlist[uname] != untrusted[uname]:
print 'Either the user already exists, or you mistyped the password,
sorry!'
#Snooze for a few secs before the connection drops...
time.sleep(3)
sys.exit('Access Denied')
#get the hell out of here, regardless! :-)
else:
sys.exit('Error')
_________________end login.py____________________
Thanks all!