Skip to content

Commit 97c660f

Browse files
committed
Merge branch 'fix-otp-generation'
2 parents 773fb05 + 71e7419 commit 97c660f

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

app/src/main/java/es/wolfi/app/passman/fragments/CredentialDisplayFragment.java

+24-16
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
import net.bierbaumer.otp_authenticator.TOTPHelper;
4747

4848
import org.apache.commons.codec.binary.Base32;
49+
import org.json.JSONException;
50+
import org.json.JSONObject;
4951

5052
import butterknife.BindView;
5153
import butterknife.ButterKnife;
@@ -132,22 +134,28 @@ public void onCreate(Bundle savedInstanceState) {
132134

133135
if (credential != null) {
134136
handler = new Handler();
135-
if (credential.getOtp().length() > 4) {
136-
otp_refresh = new Runnable() {
137-
@Override
138-
public void run() {
139-
int progress = (int) (System.currentTimeMillis() / 1000) % 30;
140-
otp_progress.setProgress(progress * 100);
141-
142-
ObjectAnimator animation = ObjectAnimator.ofInt(otp_progress, "progress", (progress + 1) * 100);
143-
animation.setDuration(1000);
144-
animation.setInterpolator(new LinearInterpolator());
145-
animation.start();
146-
147-
otp.setText(TOTPHelper.generate(new Base32().decode(credential.getOtp())));
148-
handler.postDelayed(this, 1000);
149-
}
150-
};
137+
try {
138+
JSONObject otpObj = new JSONObject(credential.getOtp());
139+
if (otpObj.has("secret") && otpObj.getString("secret").length() > 4) {
140+
String otpSecret = otpObj.getString("secret");
141+
otp_refresh = new Runnable() {
142+
@Override
143+
public void run() {
144+
int progress = (int) (System.currentTimeMillis() / 1000) % 30;
145+
otp_progress.setProgress(progress * 100);
146+
147+
ObjectAnimator animation = ObjectAnimator.ofInt(otp_progress, "progress", (progress + 1) * 100);
148+
animation.setDuration(1000);
149+
animation.setInterpolator(new LinearInterpolator());
150+
animation.start();
151+
152+
otp.setText(TOTPHelper.generate(new Base32().decode(otpSecret)));
153+
handler.postDelayed(this, 1000);
154+
}
155+
};
156+
}
157+
} catch (JSONException e) {
158+
e.printStackTrace();
151159
}
152160
} else {
153161
Toast.makeText(getContext(), getString(R.string.error_occurred), Toast.LENGTH_LONG).show();

fastlane/metadata/android/en-US/changelogs/13.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
- fix ConcurrentModificationException after editing or deleting a credential
2+
- fix OTP generation
23
- some other bug fixes
34
- unify button position
45
- replace char with character in translations

0 commit comments

Comments
 (0)