其他分享
首页 > 其他分享> > 团队冲刺08

团队冲刺08

作者:互联网

增加了忘记密码,移除密码的功能,进行密保验证。

代码:

复制代码
  @SuppressLint("CommitPrefEdits")
  private void updatePassword (String passwordText, String questionText, String answerText) {
    if (passwordText == null) {
      if (prefs.getString(PREF_PASSWORD, "").length() == 0) {
        Crouton.makeText(mActivity, R.string.password_not_set, ONStyle.WARN, croutonHandle).show();
        return;
      }
      new MaterialDialog.Builder(mActivity)
          .content(R.string.agree_unlocking_all_notes)
          .positiveText(R.string.ok)
          .onPositive((dialog, which) -> PasswordHelper.removePassword()).build().show();
    } else if (passwordText.length() == 0) {
      Crouton.makeText(mActivity, R.string.empty_password, ONStyle.WARN, croutonHandle).show();
    } else {
      Observable
          .from(DbHelper.getInstance().getNotesWithLock(true))
          .subscribeOn(Schedulers.newThread())
          .observeOn(AndroidSchedulers.mainThread())
          .doOnSubscribe(() -> prefs.edit()
                                    .putString(PREF_PASSWORD, Security.md5(passwordText))
                                    .putString(PREF_PASSWORD_QUESTION, questionText)
                                    .putString(PREF_PASSWORD_ANSWER, Security.md5(answerText))
                                    .commit())
          .doOnNext(note -> DbHelper.getInstance().updateNote(note, false))
          .doOnCompleted(() -> {
            Crouton crouton = Crouton.makeText(mActivity, R.string.password_successfully_changed, ONStyle
                .CONFIRM, croutonHandle);
            crouton.setLifecycleCallback(new LifecycleCallback() {
              @Override
              public void onDisplayed () {
                // Does nothing!
              }


              @Override
              public void onRemoved () {
                onBackPressed();
              }
            });
            crouton.show();
          })
          .subscribe();
    }
  }


  /**
   * Checks correctness of form data
   */
  private boolean checkData () {
    boolean res = true;

    if (password.getText().length() == passwordCheck.getText().length()
        && passwordCheck.getText().length() == 0) {
      return true;
    }

    boolean passwordOk = password.getText().toString().length() > 0;
    boolean passwordCheckOk = passwordCheck.getText().toString().length() > 0 && password.getText().toString()
                                                                                         .equals(
                                                                                             passwordCheck.getText().toString());
    boolean questionOk = question.getText().toString().length() > 0;
    boolean answerOk = answer.getText().toString().length() > 0;
    boolean answerCheckOk = answerCheck.getText().toString().length() > 0 && answer.getText().toString().equals
        (answerCheck.getText().toString());

    if (!passwordOk || !passwordCheckOk || !questionOk || !answerOk || !answerCheckOk) {
      res = false;
      if (!passwordOk) {
        password.setError(getString(R.string.settings_password_not_matching));
      }
      if (!passwordCheckOk) {
        passwordCheck.setError(getString(R.string.settings_password_not_matching));
      }
      if (!questionOk) {
        question.setError(getString(R.string.settings_password_question));
      }
      if (!answerOk) {
        answer.setError(getString(R.string.settings_answer_not_matching));
      }
      if (!answerCheckOk) {
        answerCheck.setError(getString(R.string.settings_answer_not_matching));
      }
    }
    return res;
  }

标签:团队,string,08,getText,length,boolean,toString,冲刺,password
来源: https://www.cnblogs.com/9d629/p/16373009.html