1 #!/usr/bin/python3 2 # coding : utf-8 3 4 def passwd_creation(passwd_length,characters_for_passwd,path_for_saving): 5 ''' The first parameter is the length of password which is type <int>; 6 The second parameter is the possiable characters for the password which is type <string>; 7 The last parameter is the path to save passwords created; 8 ''' 9 if(type(passwd_length)!=int or type(characters_for_passwd)!=str or type(path_for_saving)!=str): 10 print('Please be careful about the type of each parameter which is <int,str,str> in proper order!') 11 return False 12 if(passwd_length<0): 13 print('The length of password can\'t be less than zero!') 14 return False 15 try: 16 file=open(path_for_saving,'r') 17 flag=input('The file already exists!Are you wanne to override it?(y/n):') 18 if(flag!='y' and flag!='Y'): 19 print('The program has benn terminated!') 20 return False 21 except: 22 pass 23 try: 24 len_chars=len(characters_for_passwd) 25 with open(path_for_saving,'w') as passwd_file: 26 print('Length of the password: %d\nChosed characters: %s\nPath to save data: %s\nWriting data...'%(passwd_length,characters_for_passwd,path_for_saving)) 27 for i in range(len_chars**passwd_length): 28 passwd='' 29 temp=i 30 for j in range(passwd_length): 31 passwd=characters_for_passwd[temp%len_chars]+passwd 32 temp=temp//len_chars 33 passwd_file.write(passwd+'\n') 34 print('Completed!') 35 return True 36 except: 37 print('There is something wrong happened while writing data into the file!') 38 return False 39 40 if __name__=='__main__': 41 a=int(input('Please input the length of passwd:')) 42 b=input('Please input the possiable characters:') 43 c=input('Please input the path for saving data:') 44 passwd_creation(a,b,c)