logincheck.java
来自「国外的数据结构与算法分析用书」· Java 代码 · 共 34 行
JAVA
34 行
package Commands;
import Interfaces.Interface;
import People.Staff;
import Sets.StaffSetAccess;
import dslib.exception.ItemNotFoundUosException;
/** Check that the id entered is valid. */
public class LoginCheck
{
/** Is the id entered by the person using loginInterface valid?
Analysis: Time = O(log(StaffSet.size)) */
public static boolean valid(int id, Interface loginInterface)
{
Staff user = null;
try
{
user = (Staff) StaffSetAccess.dictionary().obtain(new Integer(id));
} catch (ItemNotFoundUosException e)
{
loginInterface.sendMessage("****Invalid id. Session terminated.");
return false;
}
String password = loginInterface.getPassword();
if (password.equals(user.password()))
return true;
else
{
loginInterface.sendMessage("****Incorrect password. Session terminated.");
return false;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?