public static String getLoggedUserName(HttpServletRequest request) throws SQLException {
        String savedLogin, savedHash;
        savedLogin = savedHash = null;
        
        Cookie[] cookies = request.getCookies();
        if(cookies != null) {
            for(Cookie c : cookies) {
                String name = c.getName();
                if(name.equals("login")) {
                    savedLogin = base64dec(c.getValue());
                }
                
                if(name.equals("hash")) {
                    savedHash = c.getValue();
                }
            }
            
            if(savedLogin != null && savedHash != null) {
                boolean loggedIn = UserManager.checkHash(savedLogin, savedHash);
                if(loggedIn) {
                    return savedLogin;
                }
            }
        }
        
        return null;
    }