i'm new to python and dont really know how to ask a question properly so please forgive me.
Really in need to guidance, is that i want to let user enter his password using input and the output is masked as asterisk,and the user input will be used to change another file info( i'm using python 3 on windows 10).
I know i could use the getpass.getpass() and showing password as asterisk is risky because it let others read and count how long is the password, but since i want to make this small app looking 'profesional' and let user feel safe then i see the need to mask the password.
And finally the output should be saved to replace another file basic info such as email, user id and password.
I've succeeded to replace all of them except the password out since it only change the entered password(mynewpassword12345) to "" .
Below are some link i got from SO said to be related to my question :
Masking user input in python with asterisks accepted answer has no direction on how to or didnt provide example.
Getting paths as user input Python 3 this accepted answer is not related to my questions.
Input only 3 characters and 3 asterisk this accepted answer also is not related to to my question.
Change EditText password mask character to asterisk (*) this accepted answer too is not related to my question.
Partial Password Masking on Input Field this accepted answer again is not related to my question.
Masking user input in python with asterisks this accepted answer is related to my question but on platform other than windows.
String to asterisk, masking password again these answers here is not related to my question.
word (password) displays in asterisks - Console application this accepted answer again is not related to my question.
Below is sample code example i got from SO answer to mask user password as asterisk ( but sorry that i forgot to save the link).
It worked on python exe(but not on idle) and is masking user password input as asterisk, but it did not let me save the printed password as user output.
So far this is what i'm trying to do, extract a zip file from certin folder in certain path, prompt user to input and add to change default info i.e email, id, and etc.
from zipfile import ZipFile
from selenium.webdriver.support.ui import WebDriverWait
import fileinput
import os
import py_compile
import shutil, glob
import textwrap
import datetime
import msvcrt
import time
import sys
script_dir = os.path.dirname(__file__)
file_path2 = os.path.join(script_dir, ' alert ' , 'temp' , 'temp folder' , 'temp' , 'myapp.zip')
##print(file_path2)
NameFile2 = file_path2
with ZipFile(NameFile2, 'r') as zf:
zf.extractall(os.path.join(script_dir, 'alert' , 'temp' , 'temp folder' , 'temp' ) , pwd=b'mypassword' )
file_path = os.path.join(script_dir, ' alert ' , 'temp' , 'temp folder' , 'temp' , 'myapp.py')
##print(file_path)
NameFile = file_path
email = "emailaddress"
password = "userpassword"
userID = "userID"
id1 = "id1"
id2 = "id2"
id3 = "id3"
id4 = "id4"
id5 = "id5"
id6 = "id6"
id7 = "id7"
id8 = "id8"
id9 = "id9"
idlast = "idlast"
level = 3
##
x = datetime.datetime.now()
text1 = '''hi, welcome to my app.
'''
#print('\t' * level, text1 )
#print(textwrap.fill(text1, 60))
print(" ")
print((x.strftime("%c")).center(80))
print(" ")
for line in textwrap.wrap(text1, width=50):
print(line.center(80))
print(" ")
newemail = input (" email : " )
#newpassword = input (" password : ")
list1 = []
def getPASS():
print("Input password")
list1 = []
while True:
char = msvcrt.getch()
char =str(char)
char = char[2:-1]
if char == "\\n'" or char == "\\r":
break
elif char == "\\x08":
del list1[-1]
os.system("cls")
print("Input password:")
sys.stdout.write("*" * len(list1))
sys.stdout.flush()
continue
else:
list1.append(char)
sys.stdout.write("*")
sys.stdout.flush()
print("\n")
psw = "".join(list1)
print(psw)
invalid = ' ,:;/?"\}]{[-=+!@#$%^&*()|'
for x in psw:
if x in invalid:
print("Character %r is not allowed in password" % x)
getPASS()
else:
pass
getPASS()
newpassword = psw
newuserID = input (" userID : ")
newid1 = input (" ID seefirst1 : ")
newid2 = input (" ID seefirst2 : ")
newid3 = input (" ID seefirst3 : ")
newid4 = input (" ID seefirst4 : ")
newid5 = input (" ID seefirst5 : ")
newid6 = input (" ID seefirst6 : ")
newid7 = input (" ID seefirst7 : ")
newid8 = input (" ID seefirst8 : ")
newid9 = input (" ID seefirst9 : ")
newidlast = input (" ID seefirst10 : ")
with fileinput.FileInput(NameFile, inplace=True, backup='.bak') as file:
for line in file:
print(line.replace(email, newemail), end='')
with fileinput.FileInput(NameFile, inplace=True, backup='.bak') as file:
for line in file:
print(line.replace(password, newpassword), end='')
with fileinput.FileInput(NameFile, inplace=True, backup='.bak') as file:
for line in file:
print(line.replace(userID, newuserID), end='')
with fileinput.FileInput(NameFile, inplace=True, backup='.bak') as file:
for line in file:
print(line.replace(id1, newid1), end='')
with fileinput.FileInput(NameFile, inplace=True, backup='.bak') as file:
for line in file:
print(line.replace(id2, newid2), end='')
with fileinput.FileInput(NameFile, inplace=True, backup='.bak') as file:
for line in file:
print(line.replace(id3, newid3), end='')
with fileinput.FileInput(NameFile, inplace=True, backup='.bak') as file:
for line in file:
print(line.replace(id4, newid4), end='')
with fileinput.FileInput(NameFile, inplace=True, backup='.bak') as file:
for line in file:
print(line.replace(id5, newid5), end='')
with fileinput.FileInput(NameFile, inplace=True, backup='.bak') as file:
for line in file:
print(line.replace(id6, newid6), end='')
with fileinput.FileInput(NameFile, inplace=True, backup='.bak') as file:
for line in file:
print(line.replace(id7, newid7), end='')
with fileinput.FileInput(NameFile, inplace=True, backup='.bak') as file:
for line in file:
print(line.replace(id8, newid8), end='')
with fileinput.FileInput(NameFile, inplace=True, backup='.bak') as file:
for line in file:
print(line.replace(id9, newid9), end='')
with fileinput.FileInput(NameFile, inplace=True, backup='.bak') as file:
for line in file:
print(line.replace(idlast, newidlast), end='')
#wait = WebDriverWait(driver, 10)
file_path3 = os.path.join(script_dir, ' alert ' , 'temp' , 'temp folder' , 'temp' , 'myapp.py')
#print(file_path3)
script = file_path3
py_compile.compile(script)
from pathlib import Path
# ...
#pathtofile = Path(__file__).parent.parent.parent.parent.parent # Path to Folder myapp
pathtoduplicate = os.path.join(script_dir ,'myapp.cpython-37.pyc')
#print(pathtoduplicate)
if os.path.exists(pathtoduplicate):
os.remove(pathtoduplicate)
else:
print("The file does not exist")
##print(pathtofile)
source_dir = os.path.join(script_dir, ' alert ' , 'temp' , 'temp folder' , 'temp' , '__pycache__') #Path to Pycache
dst = os.path.join(script_dir) # Path to myapp
files = glob.iglob(os.path.join(source_dir, "*.pyc"))
for file in files:
if os.path.isfile(file):
shutil.move(file, dst)
raise SystemExit()
i got the result i want that the input show as asterisk, but it didnt change the output and only show " " rather than actual password.
Wanted Result: Masked input password has replaced default password.
email = "mynewemail@gmail.com"
password = "mynewpassword12345"
user = "mynewnewid1"
seefirst1 = "newid1"
seefirst2 = "newid2"
seefirst3 = "newid3"
seefirst4 = "newid4"
seefirst5 = "newid5"
seefirst6 = "newid6"
seefirst7 = "newid7"
seefirst8 = "newid8"
seefirst9 = "newid9"
seefirst10 = "newid10"
Unwanted result: Masked input password didnt replace default password.
email = "mynewemail@gmail.com"
password = ""
user = "mynewnewid1"
seefirst1 = "newid1"
seefirst2 = "newid2"
seefirst3 = "newid3"
seefirst4 = "newid4"
seefirst5 = "newid5"
seefirst6 = "newid6"
seefirst7 = "newid7"
seefirst8 = "newid8"
seefirst9 = "newid9"
seefirst10 = "newid10"
Please help me solve this. I'm noob and really new to python.