Android仿支付寶手勢密碼解鎖功能_Android

來源:互聯網
上載者:User

Starting

建立手勢密碼可以查看 CreateGestureActivity.java 檔案.

登陸驗證手勢密碼可以看 GestureLoginActivity.java 檔案.

Features

使用了 JakeWharton/butterknife butterknife

使用了 ACache 來儲存手勢密碼

/**  * 儲存手勢密碼  */ private void saveChosenPattern(List<LockPatternView.Cell> cells) {  byte[] bytes = LockPatternUtil.patternToHash(cells); aCache.put(Constant.GESTURE_PASSWORD, bytes);}

Warning: 使用 ACache 類儲存密碼並不是無限期的. 具體期限可以查看 ACache 類.

使用了 SHA 演算法儲存手勢密碼

/**  * Generate an SHA-1 hash for the pattern. * Not the most secure, but it is at  * least a second level of protection. First level is that the file is in a  * location only readable by the system process.* * @param pattern  * @return the hash of the pattern in a byte array.  */public static byte[] patternToHash(List<LockPatternView.Cell> pattern) {   if (pattern == null) {     return null;  } else {    int size = pattern.size();     byte[] res = new byte[size];    for (int i = 0; i < size; i++) {      LockPatternView.Cell cell = pattern.get(i);    res[i] = (byte) cell.getIndex();   }     MessageDigest md = null;   try {    md = MessageDigest.getInstance("SHA-1");       return md.digest(res);    } catch (NoSuchAlgorithmException e) {    e.printStackTrace();       return res;   }  } }

可以開啟震動模式,當選中一個圈的時候,手機會震動

/** * Set whether the view will use tactile feedback.  *If true, there will be  * tactile feedback as the user enters the pattern.  * @param tactileFeedbackEnabled Whether tactile feedback is enabled  */ public void setTactileFeedbackEnabled(boolean tactileFeedbackEnabled) { mEnableHapticFeedback = tactileFeedbackEnabled;}

可以開啟繪製路徑隱形模式

/**  * Set whether the view is in stealth mode. If true, there will be no  * visible feedback as the user enters the pattern.  * @param inStealthMode Whether in stealth mode.  */public void setInStealthMode(boolean inStealthMode) { mInStealthMode = inStealthMode;}

Example

以上就是本文的全部內容,希望對大家的學習有所協助,也希望大家多多支援雲棲社區。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.