From cbc4718f58753759a36d8b60e7c6b2f0d37bb4fc Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Thu, 10 Jan 2013 11:19:07 +0100 Subject: Added change_password function in order to change the password corresponding to username. --- source/auth.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'source') diff --git a/source/auth.py b/source/auth.py index dbe6a1cc..cf451e7f 100755 --- a/source/auth.py +++ b/source/auth.py @@ -50,7 +50,24 @@ class excel_french(csv.Dialect): csv.register_dialect('excel_french', excel_french) - +def change_password(username, new_password, password_file='./var/password'): + """ + Change the password corresponding to username. + """ + users_list = [] + result = False + with open(password_file, 'r') as csv_readfile_read: + cr = csv.reader(csv_readfile_read, 'excel_french') + users_list = [elem for elem in cr] + with open(password_file, 'w') as csv_file_write: + cw = csv.writer(csv_file_write, 'excel_french') + for user in users_list: + if user[0] == username: + cw.writerow([user[0], new_password]) + result = True + else: + cw.writerow(user) + return result def check_credentials(username, password): """Verifies credentials for username and password. -- cgit