Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.50 KB | None | 0 0
  1. # coding: UTF-8
  2.  
  3. import random
  4.  
  5. def randompassword(set, count):
  6.     '''
  7.     This function generate password from the selected set of symbols
  8.    '''
  9.     res = '' # nulled result of the function
  10.     passes = 1 # nulled count of passes in cycle
  11.     symstr = '' # nulled used set of symbols
  12.     # in if-construction below we select symbol set
  13.     if set == 0:
  14.         symstr = unicode('qazxswedcvfrtgbnhyujmkilop', 'UTF-8')
  15.     if set == 1:
  16.         symstr = unicode('QAZXSWEDCVFRTGBNHYUJMKILOP', 'UTF-8')
  17.     if set == 2:
  18.         symstr = unicode('qazxswedcvfrtgbnhyujmkilop1234567890', 'UTF-8')
  19.     if set == 3:
  20.         symstr = unicode('QAZXSWEDCVFRTGBNHYUJMKILOP1234567890', 'UTF-8')
  21.     # cycle, what generate password
  22.     while passes != count:
  23.         res += symstr[random.randrange(0, len(symstr))]
  24.         # in string above:
  25.         # len(symstr) - length of the chosen set of symbols;
  26.         # random.randrange(0, len(symstr)) - random number from [0, length of set]
  27.         # symstr[blahblahblah] - random symbol from set
  28.         passes += 1 # cycle counter
  29.     return res
  30.  
  31. print '''Please, select one of the following sets of symbols and enter correct number:
  32. 1) qazxswedcvfrtgbnhyujmkilop
  33. 2) QAZXSWEDCVFRTGBNHYUJMKILOP
  34. 3) qazxswedcvfrtgbnhyujmkilop1234567890
  35. 4) QAZXSWEDCVFRTGBNHYUJMKILOP1234567890'''
  36. setg = int(input('> ')) - 1
  37. print 'Please, enter length.'
  38. countg = int(input('> ')) + 1
  39. print 'Generated password: ', randompassword(setg, countg), '\nPress Enter to exit'
  40.  
  41. raw_input()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement