package authentication;

public class Main {

	public static void main(String[] args) {
		AuthenticationManager am = new Authentication () ;
		// users management
		try {
		am.addUser("bob","123");
		System.out.println("Bob has been added !");
		am.removeUser("bob");
		System.out.println("Bob has been removed !");
		am.removeUser("bob");
		System.out.println("Bob has been removes twice !");
		} catch (UserUnknownException e) {
		System.out.println(e.login +" : user unknown (enable to remove)!");
		} catch (UserExistsException e) {
		System.out.println(e.login +" has already been added !");
		}
		// authentication
		try {
		am.addUser("bob","123");
		System.out.println("Bob has been added !");
		am.authentify("bob","123");
		System.out.println("Authentification OK !");
		am.authentify("bob","456");
		System.out.println("Invalid password !");
		} catch (WrongPasswordException e) {
		System.out.println(e.login+" has provided an invalid password !");
		} catch (UserExistsException e) {
		System.out.println(e.login +" has already been added !");
		} catch (UserUnknownException e) {
		System.out.println(e.login +" : user unknown (enable to remove)!");
		}
		// persistance
		try {
		am.save("users.txt");
		AuthenticationManager am1 = new Authentication();
		am1.load("users.txt");
		am1.authentify("bob","123");
		System.out.println("Loading complete !");
		} catch (UserUnknownException e) {
			System.out.println(e.login +" is unknown ! error during thesaving/loading.");
			} catch (WrongPasswordException e) {
			System.out.println(e.login+" has provided an invalid password!error during the saving/loading .");
			} catch (IOExceptionException e) {
			System.out.println(e);
			}
			}
	
}
