Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to localize reason of FirebaseAuthWeakPasswordException in Flutter?

What is the best approach to localize the reason of FirebaseAuthWeakPasswordException in Flutter?

In the official documentation a getReason() method is mentioned, but I was not able to find something like a list of potential reasons that I need to catch and localize from that method. The only documented reason for a weak password is the minimum length of 6 characters (maybe this is the only reason?!).

I also was not able to find the source code of the FirebaseAuthWeakPasswordException class and/or the source code where it is used and also not the right file to put in an import statement to import FirebaseAuthWeakPasswordException and also Google search was not helpful. So, basically I do not know where to start (except for sending random weak passwords and checking the responses, which does not guarantee that I will cover every potential reason).

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Are there any ideas / best practices how to solve the localization of the weak password exceptions of Firebase in Flutter? I would assume, I am not the only person who wants to explain to users why their password is not excepted.

>Solution :

Class description in docs:

Thrown when using a weak password (less than 6 chars) to create a new account or to update an existing account’s password. Use getReason() to get a message with the reason the validation failed that you can display to your users.

The getReason() method just returns a string than reflects the essence of an exception. And the essence is specified in the class description. So, whenever you receive FirebaseAuthWeakPasswordException, you can be sure it happens because password length is less than 6 chars.

I’m not familiar with flutter, but the logic in this case should be like this

if exception class is FirebaseAuthWeakPasswordException then
    show error with locale key = LocaleKey_ShortPassError
endif
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading