public VeneraSession login(String username, String password) throws SQLException, NoSuchAlgorithmException {
        VeneraSession sess = null;
        Connection conn = null;
        CallableStatement stmt = null;

        try {
            conn = getConnection();

            String query = "{call spr_login( ?, ?, ? )} ";

            // Get a statement from the connection
            stmt = conn.prepareCall(query);

            password = Functions.getMd5Hash(password);

            int i = 1;
            stmt.setString(i++, username);
            stmt.setString(i++, password);
            stmt.registerOutParameter(i, java.sql.Types.INTEGER);

            // Execute the query
            stmt.execute();

            boolean res = stmt.getBoolean("check_login");

            if (res) {
                // Get user by username/email
                User usr = getByEmail(username);

                // Check if user was found
                if (usr != null) {
                    RoleData rd = new RoleData();

                    // Get role related to user
                    Role role = rd.getById(usr.getRoleId());

                    // Check if role was found
                    if (role != null) {
                        sess = new VeneraSession();

                        // Fill up session information
                        sess.setLastname(usr.getLastname());
                        sess.setFirstname(usr.getFirstname());
                        sess.setEmail(usr.getEmail());
                        sess.setUserId(usr.getUserId());
                        sess.setLastname(usr.getLastname());
                        sess.setRoleName(role.getName());
                        sess.setRoleType(role.getType());
                    }
                }
            }

            stmt.close();
        } catch (SQLException ex) {
            LOGGER.error(ex.getMessage());

            throw new SQLException(ex);
        } catch (NoSuchAlgorithmException ex) {
            LOGGER.error(ex.getMessage());

            throw new NoSuchAlgorithmException(ex);
        } finally {
            if (stmt != null) {
                stmt.close();
            }

            if (conn != null) {
                conn.close();
            }
        }

        return sess;
    }