#!/bin/bash echo "Enter Username : " # read username and echo username in terminal read username echo "Enter Password : " # password is read in silent mode i.e. it will # show nothing instead of password. read -s password echo echo "Your password is read in silent mode."
passwd --stdin <username>This option indicates that passwd should read the new password from standard input, which can be a pipe. For example: # echo "userpasswd1"|passwd --stdin user1.
First sign on or “su” or “sudo” to the “root” account on Linux, run: sudo -i. Then type, passwd tom to change a password for tom user. The system will prompt you to enter a password twice.
>>> import getpass
>>> pw = getpass.getpass()
Yes, getpass
: "Prompt the user for a password without echoing."
Edit: I had not played with this module myself yet, so this is what I just cooked up (wouldn't be surprised if you find similar code all over the place, though):
import getpass
def login():
user = input("Username [%s]: " % getpass.getuser())
if not user:
user = getpass.getuser()
pprompt = lambda: (getpass.getpass(), getpass.getpass('Retype password: '))
p1, p2 = pprompt()
while p1 != p2:
print('Passwords do not match. Try again')
p1, p2 = pprompt()
return user, p1
(This is Python 3.x; use raw_input
instead of input
when using Python 2.x.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With