Skip to content

Commit

Permalink
FIX.
Browse files Browse the repository at this point in the history
Passwords fixed.
  • Loading branch information
curious-odd-man committed Apr 12, 2015
1 parent a4753bc commit 0a78fc2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
33 changes: 24 additions & 9 deletions src/db/SpecialPassword.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ private byte getSpecialCharactersCount()
return (byte) ((this.length) >>> 2);
}

private int getRandomNumberFromHex(String hash, int idx)
{
final String hexArray = "0123456789abcdef";
if (idx >= hash.length() - 1)
{
idx %= hash.length() - 1;
}

return Math
.abs(hexArray.indexOf(hash.charAt(idx)) * hexArray.indexOf(hash.charAt(idx + 1)));
}

public String getPassword(Task<Void> passwordCalculation)
{
int idx = 0;
Expand Down Expand Up @@ -189,25 +201,31 @@ public String getPassword(Task<Void> passwordCalculation)

Logger.printDebug("Password generation. STAGE 1. DONE");

Logger.printDebug(password.toString());

/*
* 2. Stage - Result of Stage 1 (appropriate length password) will be
* modified with special characters.
*/
if (paramsMask.get(ParamsMaskBits.HAS_SPECIAL_CHARACTERS.ordinal())
&& specialChars.length() != 0)
{

Logger.printDebug("Password generation. STAGE 2. START");

int count = getSpecialCharactersCount();
int specialCharacterPosition = specialHash.charAt(idx++);
int insertPosition = specialHash.charAt(idx++);
int specialCharacterPosition = 0;
int insertPosition = 0;

while (count > 0)
{
insertPosition = (insertPosition % password.length());
specialCharacterPosition = (specialCharacterPosition % specialChars.length());
do
{
insertPosition =
(getRandomNumberFromHex(specialHash, idx++) % password.length());
}
while (specialChars.indexOf(password.charAt(insertPosition)) != -1);

specialCharacterPosition =
(getRandomNumberFromHex(specialHash, idx++) % specialChars.length());

if (specialChars.length() >= getSpecialCharactersCount())
{
Expand All @@ -224,9 +242,6 @@ public String getPassword(Task<Void> passwordCalculation)

password.setCharAt(insertPosition, specialChars.charAt(specialCharacterPosition));
count--;

specialCharacterPosition = specialHash.charAt(idx++);
insertPosition = specialHash.charAt(idx++);
}

Logger.printDebug("Password generation. STAGE 2. DONE");
Expand Down
10 changes: 6 additions & 4 deletions src/utilities/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,21 @@ public static BigInteger hexToInt(String hexValue)

for (; i >= 0; --i)
{
Logger.printDebug("HEX STRING: " + hexValue.substring(i, i + 1));
// Logger.printDebug("HEX STRING: " + hexValue.substring(i, i + 1));

curr = new BigInteger(hexValue.substring(i, i + 1), 16);

Logger.printDebug("BI CURR: " + curr.toString());
// Logger.printDebug("BI CURR: " + curr.toString());

Logger.printDebug("BI POWER: " + power.toString() + ", " + pwr);
// Logger.printDebug("BI POWER: " + power.toString() + ", " + pwr);

out = out.add(curr.multiply(power.pow(pwr++)));

Logger.printDebug("BI OUT: " + out.toString());
// Logger.printDebug("BI OUT: " + out.toString());
}

Logger.printDebug("BI OUT: " + out.toString());

return out;
}
}

0 comments on commit 0a78fc2

Please sign in to comment.