From f02694fa325f67b5ed63ac813fc065aead752beb Mon Sep 17 00:00:00 2001 From: Alexandre Possebom Date: Sat, 20 Sep 2014 20:46:19 -0300 Subject: [PATCH] Fixed alphanumeric password type --- README.md | 4 ++-- twik | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 26c783e..c3f0479 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/twik b/twik index 599a451..b614e28 100755 --- a/twik +++ b/twik @@ -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)