You can do it like this, for example with the login.py script example:
if __name__ == '__main__': import sys user = sys.stdin.readline().strip() passwd = sys.stdin.readline().strip() if user == 'root' and passwd == 'password': print 'Login successful' sys.exit(0) sys.stderr.write('error: invalid username or password\n') sys.exit(1)
good-credentials.txt
root password
bad credentials.txt
user foo
Then you can do an automatic login using:
$cat good-credentials.txt | python login.py Login successful $cat bad-credentials.txt | python login.py error: invalid username or password
The downside of this approach is that you save your password in plain text, which is not a big practice.
source share