欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android仿支付宝手势密码解锁功能

程序员文章站 2024-02-27 18:26:03
starting 创建手势密码可以查看 creategestureactivity.java 文件. 登陆验证手势密码可以看 gestureloginactivit...

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

Android仿支付宝手势密码解锁功能

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。