Added numeric password type
This commit is contained in:
parent
f02694fa32
commit
0bd4c72b6e
|
@ -13,5 +13,9 @@ positional arguments:
|
||||||
-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 3 for NUMERIC
|
-p {1,2,3} 1 for ALPHANUMERIC_AND_SPECIAL_CHAR, 2 for ALPHANUMERIC and 3 for NUMERIC
|
||||||
|
|
||||||
* TODO
|
Private Key is stored in ~/twik.conf you need change it to match with chrome extension and android app:
|
||||||
* Need fix NUMERIC
|
|
||||||
|
[Profile]
|
||||||
|
private_key = TFCY2AJI-NBPU-V01E-F7CP-PJIZNRKPF25W
|
||||||
|
|
||||||
|
|
||||||
|
|
30
twik
30
twik
|
@ -86,12 +86,21 @@ def injectCharacter( input, offset, reserved, seed, length, cStart, cNum ):
|
||||||
def removeSpecialCharacters(hash,seed,length):
|
def removeSpecialCharacters(hash,seed,length):
|
||||||
inputChars = list(hash)
|
inputChars = list(hash)
|
||||||
pivot = 0
|
pivot = 0
|
||||||
for i in range(0,len(inputChars)):
|
for i in range(0,length):
|
||||||
if not inputChars[i].isdigit() and not inputChars[i].isalpha():
|
if not inputChars[i].isdigit() and not inputChars[i].isalpha():
|
||||||
inputChars[i] = chr(((seed + pivot) % 26 + ord('A')))
|
inputChars[i] = chr(((seed + pivot) % 26 + ord('A')))
|
||||||
pivot = i + 1
|
pivot = i + 1
|
||||||
return "".join(inputChars)
|
return "".join(inputChars)
|
||||||
|
|
||||||
|
def convertToDigits(hash,seed,length):
|
||||||
|
inputChars = list(hash)
|
||||||
|
pivot = 0
|
||||||
|
for i in range(0,length):
|
||||||
|
if not inputChars[i].isdigit():
|
||||||
|
inputChars[i] = chr(((seed + ord(inputChars[pivot])) % 10 + ord('0')))
|
||||||
|
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]
|
||||||
|
@ -100,16 +109,17 @@ def generateHash(tag,key,length,password_type):
|
||||||
for i in range(0, len( hash )):
|
for i in range(0, len( hash )):
|
||||||
seed += ord(hash[i])
|
seed += ord(hash[i])
|
||||||
|
|
||||||
hash = injectCharacter(hash, 0, 4, seed, length, '0', 10)
|
if password_type == PasswordType.NUMERIC:
|
||||||
|
hash = convertToDigits(hash, seed, length)
|
||||||
|
else:
|
||||||
|
hash = injectCharacter(hash, 0, 4, seed, length, '0', 10)
|
||||||
|
if password_type == PasswordType.ALPHANUMERIC_AND_SPECIAL_CHARS:
|
||||||
|
hash = injectCharacter(hash, 1, 4, seed, length, '!', 15)
|
||||||
|
hash = injectCharacter(hash, 2, 4, seed, length, 'A', 26)
|
||||||
|
hash = injectCharacter(hash, 3, 4, seed, length, 'a', 26)
|
||||||
|
|
||||||
if password_type == PasswordType.ALPHANUMERIC_AND_SPECIAL_CHARS:
|
if password_type == PasswordType.ALPHANUMERIC:
|
||||||
hash = injectCharacter(hash, 1, 4, seed, length, '!', 15)
|
hash = removeSpecialCharacters(hash, seed, length);
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
return hash[:length]
|
return hash[:length]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue