Welcome to CodeRanch, Mann Claudiu!
The problem lies in that your main method does far too much. Break up your program in steps and make separate methods for those steps.
- Prompt a user for username.
- Retrieve stored credentials for the given username.
- Prompt a user for password.
- Compare the entered password with the stored credentials.
- Authenticate a user by trying steps 3-4 three times.
These can all easily be separate methods. Your authenticate method could look something like this:
Do you see how modular code like this is much easier to read and maintain?