Home > Mobile >  How do I add a method to a PASSWORD CLASS That checks for Validity
How do I add a method to a PASSWORD CLASS That checks for Validity

Time:12-29

I created a class called password, and I tried passing a method to it that checks if the password entered is up to 8 characters which would decide its validity, please help

I tried creating a method inside the class called isValid and then calling it in the main function but that caused even more errors in my code

My code snippet below;

import 'dart:math'; 
import 'dart:core'; 
import 'dart:io'; 

void main(){ 
final myOwn = Password(); 
myOwn.value = stdin.readLineSync()!; 
print(myOwn); 
} 

class Password { 
String value = ''; 
Password(){ this.value = value; } 

toJson() { 
print('Your password is $value');
} 

@override String toString() {
return 'Your password is $value';
}

}

CodePudding user response:

You can add a method the will evaluate the stored value and return whether the value meets the program expectations. It would return true if it is a good password or false if it is not good.

class Password {
  bool isValid() => value.length > 8;
  String value = '';
}

void main() {
  final password = Password();
  password.value = stdin.readLineSync()!;
  print(password.isValid());
}
  •  Tags:  
  • dart
  • Related