forked from github/server
fix python password check scripts
This commit is contained in:
parent
0710fb796d
commit
af5f5bde60
|
@ -9,6 +9,11 @@ if len(sys.argv)<4:
|
||||||
filename=sys.argv[1]
|
filename=sys.argv[1]
|
||||||
myfaction=sys.argv[2]
|
myfaction=sys.argv[2]
|
||||||
mypasswd=sys.argv[3]
|
mypasswd=sys.argv[3]
|
||||||
|
quiet=len(sys.argv)<=4
|
||||||
|
|
||||||
|
def log(str):
|
||||||
|
if not quiet:
|
||||||
|
print(str)
|
||||||
|
|
||||||
if mypasswd[0] == '"':
|
if mypasswd[0] == '"':
|
||||||
mypasswd = mypasswd.strip('"')
|
mypasswd = mypasswd.strip('"')
|
||||||
|
@ -16,10 +21,17 @@ if mypasswd[0] == '"':
|
||||||
pw_data = EPasswd()
|
pw_data = EPasswd()
|
||||||
try:
|
try:
|
||||||
pw_data.load_database(filename)
|
pw_data.load_database(filename)
|
||||||
|
log("loaded from db " + filename)
|
||||||
except:
|
except:
|
||||||
pw_data.load_file(filename)
|
pw_data.load_file(filename)
|
||||||
|
log("loaded from file " + filename)
|
||||||
|
|
||||||
if pw_data.fac_exists(myfaction):
|
if pw_data.fac_exists(myfaction):
|
||||||
if pw_data.check(myfaction, mypasswd):
|
if pw_data.check(myfaction, mypasswd):
|
||||||
|
log("password match: " + myfaction)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
log("password mismatch: " + myfaction)
|
||||||
|
else:
|
||||||
|
log("faction missing: " + myfaction)
|
||||||
|
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
|
@ -69,7 +69,7 @@ class EPasswd:
|
||||||
def check(self, id, passwd):
|
def check(self, id, passwd):
|
||||||
pw = self.get_passwd(id)
|
pw = self.get_passwd(id)
|
||||||
if pw[0:4]=='$2a$' or pw[0:4]=='$2y$':
|
if pw[0:4]=='$2a$' or pw[0:4]=='$2y$':
|
||||||
return bcrypt.checkpw(passwd, pw)
|
return bcrypt.checkpw(passwd.encode('utf8'), pw.encode('utf8'))
|
||||||
return pw == passwd
|
return pw == passwd
|
||||||
|
|
||||||
def get_passwd(self, id):
|
def get_passwd(self, id):
|
||||||
|
|
Loading…
Reference in New Issue