zoukankan      html  css  js  c++  java
  • 第二阶段冲刺03

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

    代码:

      @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;
      }
  • 相关阅读:
    [leetcode] Delete Operation for Two Strings
    [leetcode] Minimum ASCII Delete Sum for Two Strings
    [leetcode] Palindromic Substrings
    [leetcode] Student Attendance Record I
    [leetcode] Reverse String II
    [leetcode] Diameter of Binary Tree
    [leetcode] Climbing Stairs
    [leetcode] Range Sum Query
    Codeforces 1294A Collecting Coins
    团体程序设计天梯赛 L2-021 点赞狂魔 (25分)
  • 原文地址:https://www.cnblogs.com/xjmm/p/13060778.html
Copyright © 2011-2022 走看看