how to use getpass in python

vansoking 1 Tallied Votes 350 Views Share
#! /usr/bin/env python
#filename:pwd.py
# development environment:python2.51


import getpass
usr=getpass.getuser()


while True:
    pwd=getpass.getpass("passwd:%s:" % usr)
    if pwd=='123':
        print "welcome to python!!!!"
        break
    else:
        print "The password you entered is incorrect"
Gribouillis 1,391 Programming Explorer Team Colleague

Notice getpass.getuser() which finds your login name (does it work on mac ?).

vansoking 0 Newbie Poster

I'm not sure it work on mac
getpass.getuser() Return the “login name” of the user. Availability: Unix, Windows.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.