mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-31 14:05:33 +00:00
Remove the files.
git-svn-id: svn://bind10.isc.org/svn/bind10/branches/parkinglot@654 e5f2f494-b856-4b98-b285-d166d9295462
This commit is contained in:
@@ -1,5 +0,0 @@
|
|||||||
Create user and its password by run the following command:
|
|
||||||
|
|
||||||
python usr_mgr.py
|
|
||||||
|
|
||||||
The user and its password is saved in file 'passwd.csv'.
|
|
@@ -1,56 +0,0 @@
|
|||||||
'''
|
|
||||||
This file implements user management program. The user name and
|
|
||||||
its password is saved in csv file.
|
|
||||||
'''
|
|
||||||
|
|
||||||
import random
|
|
||||||
from hashlib import sha1
|
|
||||||
|
|
||||||
import csv
|
|
||||||
|
|
||||||
class PasswordHash(object):
|
|
||||||
def __init__(self, password_):
|
|
||||||
self.salt = "".join(chr(random.randint(33, 127)) for x in range(64))
|
|
||||||
self.saltedpw = sha1((password_ + self.salt).encode()).hexdigest()
|
|
||||||
|
|
||||||
def check_password(self, password_):
|
|
||||||
"""checks if the password is correct"""
|
|
||||||
return self.saltedpw == sha1((password_ + self.salt).encode()).hexdigest()
|
|
||||||
|
|
||||||
# Note: a secure application would never store passwords in plaintext in the source code
|
|
||||||
def check_username(name):
|
|
||||||
csvfile = open('passwd.csv')
|
|
||||||
ret = 0
|
|
||||||
reader = csv.reader(csvfile)
|
|
||||||
for row in reader:
|
|
||||||
if name == row[0]:
|
|
||||||
ret = 1
|
|
||||||
break
|
|
||||||
|
|
||||||
csvfile.close()
|
|
||||||
return ret
|
|
||||||
|
|
||||||
def save_info(name,pw,salt):
|
|
||||||
csvfile = open('passwd.csv', 'a')
|
|
||||||
writer = csv.writer(csvfile)
|
|
||||||
writer.writerow([name, pw, salt])
|
|
||||||
csvfile.close()
|
|
||||||
|
|
||||||
def register():
|
|
||||||
flag = True
|
|
||||||
# create the file if it doesn't exist
|
|
||||||
csvfile = open('passwd.csv', "w")
|
|
||||||
csvfile.close()
|
|
||||||
while flag :
|
|
||||||
username = input("username:")
|
|
||||||
passwd = input("passwd:")
|
|
||||||
if check_username(username):
|
|
||||||
print("the usename already exist!")
|
|
||||||
else :
|
|
||||||
pwhash = PasswordHash(passwd)
|
|
||||||
save_info(username,pwhash.saltedpw, pwhash.salt)
|
|
||||||
print("register success!")
|
|
||||||
flag = False
|
|
||||||
|
|
||||||
register()
|
|
||||||
|
|
Reference in New Issue
Block a user