Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # coding: UTF-8
- import random
- def randompassword(set, count):
- '''
- This function generate password from the selected set of symbols
- '''
- res = '' # nulled result of the function
- passes = 1 # nulled count of passes in cycle
- symstr = '' # nulled used set of symbols
- # in if-construction below we select symbol set
- if set == 0:
- symstr = unicode('qazxswedcvfrtgbnhyujmkilop', 'UTF-8')
- if set == 1:
- symstr = unicode('QAZXSWEDCVFRTGBNHYUJMKILOP', 'UTF-8')
- if set == 2:
- symstr = unicode('qazxswedcvfrtgbnhyujmkilop1234567890', 'UTF-8')
- if set == 3:
- symstr = unicode('QAZXSWEDCVFRTGBNHYUJMKILOP1234567890', 'UTF-8')
- # cycle, what generate password
- while passes != count:
- res += symstr[random.randrange(0, len(symstr))]
- # in string above:
- # len(symstr) - length of the chosen set of symbols;
- # random.randrange(0, len(symstr)) - random number from [0, length of set]
- # symstr[blahblahblah] - random symbol from set
- passes += 1 # cycle counter
- return res
- print '''Please, select one of the following sets of symbols and enter correct number:
- 1) qazxswedcvfrtgbnhyujmkilop
- 2) QAZXSWEDCVFRTGBNHYUJMKILOP
- 3) qazxswedcvfrtgbnhyujmkilop1234567890
- 4) QAZXSWEDCVFRTGBNHYUJMKILOP1234567890'''
- setg = int(input('> ')) - 1
- print 'Please, enter length.'
- countg = int(input('> ')) + 1
- print 'Generated password: ', randompassword(setg, countg), '\nPress Enter to exit'
- raw_input()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement