-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_password_MODIFIED.py
78 lines (58 loc) · 3.71 KB
/
new_password_MODIFIED.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#******************************************************#
#File Name: new_password.py
#Version/Date: FINAL (2020-06-02)
#Programmer/ID: Teh Su Anne (1191101019)
#Project Name: Random Password Generator
#Teammates: Leong Xin-Nan, Chin Pei Wern, Ooi Kher Ning
#Course/Term: PSP0201 Mini IT Project (2019/20 T3)
#******************************************************#
import csv
import os.path
from os import path
fieldnames2 = ["Facebook", "Instagram", "Twitter", "Snapchat", "LinkedIn","Google+","Youtube", "Pinterest", "Tumblr", "Reddit", "Quora", "Others"]
#---------------------------------------- generate password ------------------------------------------#
def generatePassword(pwlength,alphalower,alphaupper,digit,specialchar):
#use ASCII table to generate password
import string
import random
password = ""
for i in range (0,pwlength):
if alphalower == 1 and alphaupper == 0 and digit == 0 and specialchar == 0:
char = string.ascii_lowercase
elif alphalower == 0 and alphaupper == 1 and digit == 0 and specialchar == 0:
char = string.ascii_uppercase
elif alphalower == 0 and alphaupper == 0 and digit == 1 and specialchar == 0:
char = string.digits
elif alphalower == 0 and alphaupper == 0 and digit == 0 and specialchar == 1:
char = string.punctuation
elif alphalower == 1 and alphaupper == 1 and digit == 0 and specialchar == 0:
char = string.ascii_lowercase + string.ascii_uppercase
elif alphalower == 1 and alphaupper == 0 and digit == 1 and specialchar == 0:
char = string.ascii_lowercase + string.digits
elif alphalower == 1 and alphaupper == 0 and digit == 0 and specialchar == 1:
char = string.ascii_lowercase + string.punctuation
elif alphalower == 0 and alphaupper == 1 and digit == 1 and specialchar == 0:
char = string.ascii_uppercase + string.digits
elif alphalower == 0 and alphaupper == 1 and digit == 0 and specialchar == 1:
char = string.ascii_uppercase + string.punctuation
elif alphalower == 0 and alphaupper == 0 and digit == 1 and specialchar == 1:
char = string.digits + string.punctuation
elif alphalower == 1 and alphaupper == 1 and digit == 1 and specialchar == 0:
char = string.ascii_lowercase + string.ascii_uppercase + string.digits
elif alphalower == 1 and alphaupper == 1 and digit == 0 and specialchar == 1:
char = string.ascii_lowercase + string.ascii_uppercase + string.punctuation
elif alphalower == 1 and alphaupper == 0 and digit == 1 and specialchar == 1:
char = string.ascii_lowercase + string.digits + string.punctuation
elif alphalower == 0 and alphaupper == 1 and digit == 1 and specialchar == 1:
char = string.ascii_uppercase + string.digits + string.punctuation
elif alphalower == 1 and alphaupper == 1 and digit == 1 and specialchar == 1:
char = string.ascii_lowercase + string.ascii_uppercase + string.digits + string.punctuation
#randomly generate a combination of password based on the user's choice by using ascii table
word = random.choice(char)
password = password + word
return password
#----------------------------------------- save password into csv ------------------------------------#
def savePassword(user,pw,selectedcat):
with open('./Passwords/'+user+'.csv','a+',newline='') as passwordfile:
writer = csv.DictWriter(passwordfile,fieldnames=fieldnames2)
writer.writerow({selectedcat:pw})