@Override
 public void createLoginSession(User user) {
   editor.putBoolean(IS_LOGGED_IN, true);
   editor.putString(KEY_NAME, user.getName());
   editor.putString(USER_NAME, user.getUserName());
   editor.commit();
 }
  @Override
  public User getLoggedInUser() {
    if (isLoggedIn()) {
      User user = new User();
      user.setName(pref.getString(KEY_NAME, null));
      user.setUserName(pref.getString(USER_NAME, null));

      return user;
    }
    ;

    return null;
  }
  @Override
  public User.LoginAction login(User user) {
    DataBaseHelper helper = new DataBaseHelper(AppUtil.CONTEXT);
    SQLiteDatabase db = helper.getReadableDatabase();
    User.LoginAction loginAction = User.LoginAction.USER_DO_NOT_EXISTS;

    String where = UserContract.USER_NAME + " = ?";
    String[] args = {user.getUserName()};
    Cursor cursor =
        db.query(UserContract.TABLE, UserContract.COLUMNS, where, args, null, null, null);

    User dataBaseUser = UserContract.bind(cursor);

    db.close();
    helper.close();

    if (dataBaseUser != null) {
      String loginPassword =
          PasswordUtil.generatePasswordHash(user.getPassword(), dataBaseUser.getSalt());

      if (loginPassword.equals(dataBaseUser.getPassword())) {
        loginAction = User.LoginAction.SUCCESS;
        dataBaseUser.createLoginSession();
      } else loginAction = User.LoginAction.INVALID_PASSWORD;
    }

    return loginAction;
  }