Fixed alphanumeric password type

This commit is contained in:
Alexandre Possebom 2014-09-20 20:46:19 -03:00
parent 2a6525758a
commit f02694fa32
2 changed files with 15 additions and 2 deletions

View File

@ -11,7 +11,7 @@ positional arguments:
optional arguments:
-h, --help show this help message and exit
-c C length of generated password
-p {1,2,3} 1 for ALPHANUMERIC_AND_SPECIAL_CHAR, 2 for ALPHANUMERIC and 3for NUMERIC
-p {1,2,3} 1 for ALPHANUMERIC_AND_SPECIAL_CHAR, 2 for ALPHANUMERIC and 3 for NUMERIC
* TODO
* Only ALPHANUMERIC_AND_SPECIAL_CHAR password type is working
* Need fix NUMERIC

13
twik
View File

@ -82,6 +82,16 @@ def injectCharacter( input, offset, reserved, seed, length, cStart, cNum ):
tail = input[pos+1:] if (pos + 1 < len(input)) else input
return head + chr(inject) + tail
def removeSpecialCharacters(hash,seed,length):
inputChars = list(hash)
pivot = 0
for i in range(0,len(inputChars)):
if not inputChars[i].isdigit() and not inputChars[i].isalpha():
inputChars[i] = chr(((seed + pivot) % 26 + ord('A')))
pivot = i + 1
return "".join(inputChars)
def generateHash(tag,key,length,password_type):
digest = hmac.new(key,tag,sha1).digest();
hash = digest.encode('base64')[:-2]
@ -95,6 +105,9 @@ def generateHash(tag,key,length,password_type):
if password_type == PasswordType.ALPHANUMERIC_AND_SPECIAL_CHARS:
hash = injectCharacter(hash, 1, 4, seed, length, '!', 15)
if password_type == PasswordType.ALPHANUMERIC:
hash = removeSpecialCharacters(hash, seed, length);
hash = injectCharacter(hash, 2, 4, seed, length, 'A', 26)
hash = injectCharacter(hash, 3, 4, seed, length, 'a', 26)