package com.sf._02_hashmap.demo3;

import java.util.HashMap;
import java.util.Map;

public class LoginService {
    private Map<String,User> map = new HashMap<>();

    public LoginService() {
        map.put("zhangsan",new User("zhangsan","123"));
        map.put("lisi",new User("lisi","123"));
    }

    public void login(User user){
        String username = user.getUsername();
        // 1 根据用户上map 获取信息看是否存在
        if(!map.containsKey(username)){
            System.out.println("账号不存在");
            return;
        }
        User mapUser = map.get(username);
        // 2 如果存在比对密码
        if(mapUser.getPassword().equals(user.getPassword())){
            System.out.println("登录成功");
        }else{
            System.out.println("登录失败");
        }
    }
}
