Fixed alphanumeric password type
This commit is contained in:
parent
2a6525758a
commit
f02694fa32
|
@ -11,7 +11,7 @@ positional arguments:
|
||||||
optional arguments:
|
optional arguments:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
-c C length of generated password
|
-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
|
* TODO
|
||||||
* Only ALPHANUMERIC_AND_SPECIAL_CHAR password type is working
|
* Need fix NUMERIC
|
||||||
|
|
13
twik
13
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
|
tail = input[pos+1:] if (pos + 1 < len(input)) else input
|
||||||
return head + chr(inject) + tail
|
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):
|
def generateHash(tag,key,length,password_type):
|
||||||
digest = hmac.new(key,tag,sha1).digest();
|
digest = hmac.new(key,tag,sha1).digest();
|
||||||
hash = digest.encode('base64')[:-2]
|
hash = digest.encode('base64')[:-2]
|
||||||
|
@ -95,6 +105,9 @@ def generateHash(tag,key,length,password_type):
|
||||||
if password_type == PasswordType.ALPHANUMERIC_AND_SPECIAL_CHARS:
|
if password_type == PasswordType.ALPHANUMERIC_AND_SPECIAL_CHARS:
|
||||||
hash = injectCharacter(hash, 1, 4, seed, length, '!', 15)
|
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, 2, 4, seed, length, 'A', 26)
|
||||||
hash = injectCharacter(hash, 3, 4, seed, length, 'a', 26)
|
hash = injectCharacter(hash, 3, 4, seed, length, 'a', 26)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue