100 lines
4.9 KiB
Java
100 lines
4.9 KiB
Java
|
package com.discord.utilities.auth;
|
||
|
|
||
|
import android.annotation.SuppressLint;
|
||
|
import android.util.Patterns;
|
||
|
import androidx.annotation.StringRes;
|
||
|
import androidx.core.app.NotificationCompat;
|
||
|
import com.discord.R;
|
||
|
import com.discord.utilities.string.StringUtilsKt;
|
||
|
import com.discord.utilities.time.ClockFactory;
|
||
|
import com.discord.utilities.view.validators.BasicTextInputValidator;
|
||
|
import com.discord.utilities.view.validators.Input;
|
||
|
import com.discord.utilities.view.validators.InputValidator;
|
||
|
import com.discord.utilities.view.validators.ValidationManager;
|
||
|
import com.google.android.material.textfield.TextInputLayout;
|
||
|
import d0.c0.d;
|
||
|
import d0.g0.t;
|
||
|
import d0.g0.w;
|
||
|
import d0.t.n;
|
||
|
import d0.z.d.m;
|
||
|
import java.net.URLEncoder;
|
||
|
import java.util.Objects;
|
||
|
/* compiled from: AuthUtils.kt */
|
||
|
public final class AuthUtils {
|
||
|
public static final String AUTHY_PACKAGE = "com.authy.authy";
|
||
|
public static final String GOOGLE_AUTHENTICATOR_PACKAGE = "com.google.android.apps.authenticator2";
|
||
|
public static final AuthUtils INSTANCE = new AuthUtils();
|
||
|
private static final int MAX_PASSWORD_LENGTH = 128;
|
||
|
private static final int MIN_PASSWORD_LENGTH = 6;
|
||
|
public static final String URL_AUTHY = "https://play.google.com/store/apps/details?id=com.authy.authy";
|
||
|
public static final String URL_GOOGLE_AUTHENTICATOR = "https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2";
|
||
|
private static final String URL_PLAY_STORE = "https://play.google.com/store/apps/details";
|
||
|
|
||
|
private AuthUtils() {
|
||
|
}
|
||
|
|
||
|
public static final /* synthetic */ boolean access$isValidEmail(AuthUtils authUtils, String str) {
|
||
|
return authUtils.isValidEmail(str);
|
||
|
}
|
||
|
|
||
|
private final boolean isValidEmail(String str) {
|
||
|
return (str.length() > 0) && Patterns.EMAIL_ADDRESS.matcher(str).matches();
|
||
|
}
|
||
|
|
||
|
public final InputValidator<TextInputLayout> createDiscriminatorInputValidator(@StringRes int i, @StringRes int i2) {
|
||
|
return new AuthUtils$createDiscriminatorInputValidator$1(i, i2);
|
||
|
}
|
||
|
|
||
|
public final BasicTextInputValidator createEmailInputValidator(@StringRes int i) {
|
||
|
return new BasicTextInputValidator(i, AuthUtils$createEmailInputValidator$1.INSTANCE);
|
||
|
}
|
||
|
|
||
|
public final ValidationManager createEmailValidationManager(TextInputLayout textInputLayout) {
|
||
|
m.checkNotNullParameter(textInputLayout, "emailInput");
|
||
|
return new ValidationManager(new Input.TextInputLayoutInput(NotificationCompat.CATEGORY_EMAIL, textInputLayout, BasicTextInputValidator.Companion.createRequiredInputValidator(R.string.email_required), createEmailInputValidator(R.string.email_invalid)));
|
||
|
}
|
||
|
|
||
|
public final BasicTextInputValidator createPasswordInputValidator(@StringRes int i) {
|
||
|
return new BasicTextInputValidator(i, AuthUtils$createPasswordInputValidator$1.INSTANCE);
|
||
|
}
|
||
|
|
||
|
public final BasicTextInputValidator createPhoneInputValidator(@StringRes int i) {
|
||
|
return new BasicTextInputValidator(i, AuthUtils$createPhoneInputValidator$1.INSTANCE);
|
||
|
}
|
||
|
|
||
|
@SuppressLint({"DefaultLocale"})
|
||
|
public final String encodeTotpSecret(String str) {
|
||
|
m.checkNotNullParameter(str, "secret");
|
||
|
String replace$default = t.replace$default(str, " ", "", false, 4, (Object) null);
|
||
|
Objects.requireNonNull(replace$default, "null cannot be cast to non-null type java.lang.String");
|
||
|
String upperCase = replace$default.toUpperCase();
|
||
|
m.checkNotNullExpressionValue(upperCase, "(this as java.lang.String).toUpperCase()");
|
||
|
Objects.requireNonNull(upperCase, "null cannot be cast to non-null type kotlin.CharSequence");
|
||
|
return w.trim(upperCase).toString();
|
||
|
}
|
||
|
|
||
|
@SuppressLint({"DefaultLocale"})
|
||
|
public final String generateNewTotpKey() {
|
||
|
String encode = URLEncoder.encode(StringUtilsKt.encodeToBase32String(d.Random(ClockFactory.get().currentTimeMillis()).nextBytes(10)), "utf-8");
|
||
|
m.checkNotNullExpressionValue(encode, "URLEncoder\n .enco…oBase32String(), \"utf-8\")");
|
||
|
String replace$default = t.replace$default(encode, "=", "", false, 4, (Object) null);
|
||
|
Objects.requireNonNull(replace$default, "null cannot be cast to non-null type java.lang.String");
|
||
|
String lowerCase = replace$default.toLowerCase();
|
||
|
m.checkNotNullExpressionValue(lowerCase, "(this as java.lang.String).toLowerCase()");
|
||
|
Objects.requireNonNull(lowerCase, "null cannot be cast to non-null type kotlin.CharSequence");
|
||
|
StringBuilder sb = new StringBuilder(w.trim(lowerCase).toString());
|
||
|
for (Number number : n.listOf((Object[]) new Integer[]{12, 8, 4})) {
|
||
|
sb.insert(number.intValue(), " ");
|
||
|
}
|
||
|
String sb2 = sb.toString();
|
||
|
m.checkNotNullExpressionValue(sb2, "builder.toString()");
|
||
|
return sb2;
|
||
|
}
|
||
|
|
||
|
public final boolean isValidPasswordLength(String str) {
|
||
|
m.checkNotNullParameter(str, "password");
|
||
|
int length = str.length();
|
||
|
return 6 <= length && 128 >= length;
|
||
|
}
|
||
|
}
|