package mit.login;

import javax.servlet.ServletContext;

/**
 * <p>Utility class with various functions for the Login server.</p>
 *
 * <p>There can only be one instance of the LoginUtil, you get to
 * it via a call to LoginUtil.getInstance().</p>
 */

public class LoginUtil {
    private static LoginUtil me = new LoginUtil();
    ServletContext context;

    private LoginUtil() {
    }

    /**
     * Obtain a reference to the one LoginUtil object in the system.
     *
     * @return the LoginUtil object
     */

    public static LoginUtil getInstance() {
	return (me);
    }

    public void setContext(ServletContext context) {
	this.context = context;
    }

    /**
     * Verify username and password.
     * Returns if true if username and password match.
     *
     * @param login The username.
     * @param password Username's Kerberos password
     * @return true if username/password are correct.
     * @exception KVerifyException on a problem.
     */
    public boolean LoginOK(String login, String password) throws KVerifyException {
	try {
	    return (KVerify.verify(login, "", password));
	} catch (Exception e) {
	    context.log(e, "Verifying login");
	    throw new KVerifyException(e.toString());
	}
    }
}
