Skip to content

Instantly share code, notes, and snippets.

@leonus96
Created October 31, 2023 02:25
Show Gist options
  • Save leonus96/3e888c70784382bca8b452860014b442 to your computer and use it in GitHub Desktop.
Save leonus96/3e888c70784382bca8b452860014b442 to your computer and use it in GitHub Desktop.
3. contraseña_v2
///Ejercicio 3 - Validación de Contraseña:
/// Escribe una función que verifique si una
/// contraseña es válida. La contraseña
/// debe tener al menos 8 caracteres y un número.
void main() {
final password = 'dsdsdsdsdsdsd';
if(validatePassword(password)) {
print('Contraseña válida');
} else {
print('Contraseña inválida');
}
}
bool validatePassword(String password) {
final size = password.length;
if (size < 8) {
return false;
}
for (int i = 0; i < password.length; i++) {
for(int j = 1; j < 10; j++) {
if(password[i] == j.toString()) {
return true;
}
}
}
return false;
}
/// contraseña => '12345678';
/// '1' '2' '3' '4' '5' '6' '7' '8'
// v1 : == '1' || == '2' ...
// v2 : == 1.toString() ==> '1'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment