Fix create account validation.
- The create account transaction is paid by our faucet, for that reason we won't let users register premium account names for now. A couple of validations were added to make sure the account the user wants to create is not premium: account length has to be greater than 2 chars, account name has to start with a letter, and restrictions like having at least one dash, number or no vowels.
This commit is contained in:
parent
544b79321b
commit
48f6304fd3
4 changed files with 37 additions and 14 deletions
|
@ -44,7 +44,8 @@ class CreateAccountFragment : BaseAccountFragment() {
|
|||
private const val TAG = "CreateAccountFragment"
|
||||
|
||||
private const val BRAINKEY_FILE = "brainkeydict.txt"
|
||||
private const val MIN_ACCOUNT_NAME_LENGTH = 8
|
||||
private const val MIN_ACCOUNT_NAME_LENGTH = 3
|
||||
private const val MAX_ACCOUNT_NAME_LENGTH = 16
|
||||
|
||||
// Used when trying to validate that the account name is available
|
||||
private const val RESPONSE_GET_ACCOUNT_BY_NAME_VALIDATION = 1
|
||||
|
@ -121,7 +122,13 @@ class CreateAccountFragment : BaseAccountFragment() {
|
|||
private fun validateAccountName(accountName: String) {
|
||||
isAccountValidAndAvailable = false
|
||||
|
||||
if ( !isAccountNameValid(accountName) ) {
|
||||
if ( !isAccountLengthValid(accountName) ) {
|
||||
tilAccountName.helperText = ""
|
||||
tilAccountName.error = getString(R.string.error__invalid_account_length)
|
||||
} else if ( !isAccountStartValid(accountName) ) {
|
||||
tilAccountName.helperText = ""
|
||||
tilAccountName.error = getString(R.string.error__invalid_account_start)
|
||||
} else if ( !isAccountNameValid(accountName) ) {
|
||||
tilAccountName.helperText = ""
|
||||
tilAccountName.error = getString(R.string.error__invalid_account_name)
|
||||
} else {
|
||||
|
@ -136,15 +143,29 @@ class CreateAccountFragment : BaseAccountFragment() {
|
|||
enableDisableCreateButton()
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies if the account length is valid, so that the faucet does not pay for a premium account.
|
||||
*/
|
||||
private fun isAccountLengthValid(accountName: String): Boolean {
|
||||
return accountName.length in MIN_ACCOUNT_NAME_LENGTH..MAX_ACCOUNT_NAME_LENGTH
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies if the account start is valid, the account name should start with a letter.
|
||||
*/
|
||||
private fun isAccountStartValid(accountName: String): Boolean {
|
||||
return accountName[0].isLetter()
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used to determine if the account name entered by the user is valid
|
||||
* @param accountName The proposed account name
|
||||
* @return True if the name is valid, false otherwise
|
||||
*/
|
||||
private fun isAccountNameValid(accountName: String): Boolean {
|
||||
return accountName.length >= MIN_ACCOUNT_NAME_LENGTH &&
|
||||
(accountName.containsDigits() || !accountName.containsVowels()) &&
|
||||
!accountName.contains("_")
|
||||
return accountName.contains("-") ||
|
||||
accountName.containsDigits() ||
|
||||
!accountName.containsVowels()
|
||||
}
|
||||
|
||||
private fun validatePIN() {
|
||||
|
@ -181,8 +202,7 @@ class CreateAccountFragment : BaseAccountFragment() {
|
|||
|
||||
override fun handleJsonRpcResponse(response: JsonRpcResponse<*>) {
|
||||
if (responseMap.containsKey(response.id)) {
|
||||
val responseType = responseMap[response.id]
|
||||
when (responseType) {
|
||||
when (responseMap[response.id]) {
|
||||
RESPONSE_GET_ACCOUNT_BY_NAME_VALIDATION -> handleAccountNameValidation(response.result)
|
||||
RESPONSE_GET_ACCOUNT_BY_NAME_CREATED -> handleAccountNameCreated(response.result)
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import android.view.inputmethod.InputMethodManager
|
|||
import android.widget.Toast
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import java.util.regex.Pattern
|
||||
|
||||
/**
|
||||
* Creates an enabled state, by enabling the button and using the given [colorResource] to color it.
|
||||
|
@ -37,14 +36,14 @@ fun Context.toast(message: CharSequence, duration: Int = Toast.LENGTH_SHORT) {
|
|||
* Verifies that the current string contains at least one digit
|
||||
*/
|
||||
fun String.containsDigits(): Boolean {
|
||||
return Pattern.matches("\\d", this)
|
||||
return this.matches(".*\\d.*".toRegex())
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that the current string contains at least one vowel
|
||||
*/
|
||||
fun String.containsVowels(): Boolean {
|
||||
return Pattern.matches("[aeiou]", this)
|
||||
return matches(".*[aeiou].*".toRegex())
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,9 +24,11 @@
|
|||
<!-- Create Account -->
|
||||
<string name="text__bitshares_account_name">Cuenta de BitShares</string>
|
||||
<string name="error__read_dict_file">Error al leer el archivo de diccionario</string>
|
||||
<string name="error__invalid_account_name">La cuenta debe de tener más de 8 caracteres, contener un número o no contener vocales. El guion bajo no es permitido. </string>
|
||||
<string name="error__invalid_account_length">La cuenta debe tener entre 3 y 16 caracteres.</string>
|
||||
<string name="error__invalid_account_start">La cuenta debe empezar con una letra.</string>
|
||||
<string name="error__invalid_account_name">Por favor ingresa un nombre regular que contenga al menos un guion, un número, o ninguna vocal.</string>
|
||||
<string name="text__verifying_account_availability">Verificando disponibilidad de cuenta…</string>
|
||||
<string name="error__account_not_available">Cuenta no disponible</string>
|
||||
<string name="error__account_not_available">Esta cuenta ya ha sido tomada.</string>
|
||||
<string name="text__account_is_available">Cuenta disponible</string>
|
||||
<string name="title_error">Error</string>
|
||||
<string name="error__faucet">El servidor regresó un error. Puede ser causado por una limitación a propósito para rechazar peticiones frecuentes provenientes de la misma dirección IP en un periodo corto de tiempo. Por favor espera 5 minutos e intenta de nuevo, o cambia a una red diferente, por ejemplo de WiFi a celular.</string>
|
||||
|
|
|
@ -24,9 +24,11 @@
|
|||
<!-- Create Account -->
|
||||
<string name="text__bitshares_account_name">BitShares account name</string>
|
||||
<string name="error__read_dict_file">Error reading dictionary file</string>
|
||||
<string name="error__invalid_account_name">The account name has to either have more than 8 characters, contain a number or have no vowels. The underscore character is also not allowed. </string>
|
||||
<string name="error__invalid_account_length">Account name should be 3 to 16 characters.</string>
|
||||
<string name="error__invalid_account_start">Account name should start with a letter.</string>
|
||||
<string name="error__invalid_account_name">Please enter a regular name containing at least one dash, a number, or no vowels.</string>
|
||||
<string name="text__verifying_account_availability">Verifying account availability…</string>
|
||||
<string name="error__account_not_available">Account not available</string>
|
||||
<string name="error__account_not_available">That account name is already taken.</string>
|
||||
<string name="text__account_is_available">Account is available</string>
|
||||
<string name="title_error">Error</string>
|
||||
<string name="error__faucet">The server returned an error. This might be due to a limitation purposefully set in place to disallow frequent requests coming from the same IP address in a short time lapse. Please wait 5 minutes and try again, or switch to a different network, for example from wifi to cell.</string>
|
||||
|
|
Loading…
Reference in a new issue