j256 / two-factor-auth

Two Factor Authentication Java code implementing the Time-based One-time Password Algorithm
ISC License
319 stars 110 forks source link

Separate otpauth portion of QR Url #6

Closed jball closed 7 years ago

jball commented 7 years ago

This would allow using another QR code generator, including a JS solution.

/**
 * Return the otpauth part of the QR image. This can be used to generate the QR code within this app or outside
 * (e.g. JS generator)
 *
 * @param keyId
 *            Name of the key that you want to show up in the users authentication application. Should already be
 *            URL encoded.
 * @param secret
 *            Secret string that will be used when generating the current number.
 */
public static String otpauthUrl(String keyId, String secret) {
    StringBuilder sb = new StringBuilder(128);
    sb.append("otpauth://totp/").append(keyId).append("%3Fsecret%3D").append(secret);
    return sb.toString();
}
j256 commented 7 years ago

Good idea.

j256 commented 7 years ago

Committed. Thanks again.

jball commented 7 years ago

No problem, thank you!