use of com.google.authenticator.blackberry.AccountDb.OtpType in project google-authenticator by google.
the class AuthenticatorScreen method computeAndDisplayPin.
/**
* Computes the PIN and saves it in mUsers. This currently runs in the UI
* thread so it should not take more than a second or so. If necessary, we can
* move the computation to a background thread.
*
* @param user the user email to display with the PIN
* @param position the index for the screen of this user and PIN
* @param computeHotp true if we should increment counter and display new hotp
*
* @return the generated PIN
*/
String computeAndDisplayPin(String user, int position, boolean computeHotp) {
OtpType type = AccountDb.getType(user);
String secret = getSecret(user);
PinInfo currentPin;
if (mUsers[position] != null) {
// existing PinInfo, so we'll update it
currentPin = mUsers[position];
} else {
currentPin = new PinInfo();
currentPin.mPin = sResources.getString(EMPTY_PIN);
}
currentPin.mUser = user;
if (type == OtpType.TOTP) {
currentPin.mPin = computePin(secret, null);
} else if (type == OtpType.HOTP) {
currentPin.mIsHotp = true;
if (computeHotp) {
AccountDb.incrementCounter(user);
Integer counter = AccountDb.getCounter(user);
currentPin.mPin = computePin(secret, new Long(counter.longValue()));
}
}
mUsers[position] = currentPin;
return currentPin.mPin;
}
Aggregations