Android判断输入密码的强度

先上效果图






psd_edt.addTextChangedListener(new TextWatcher() {

			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
				String str = psd_edt.getText().toString().trim();
				int length = str.length();
				if (length > 0) {
					if (!AbStrUtil.isNumberLetter(str)) {
						str = str.substring(0, length - 1);
						psd_edt.setText(str);
						String str1 = psd_edt.getText().toString().trim();
						psd_edt.setSelection(str1.length());
						psd_edt.setError("密码只能是字母和数字");
					}
				}
				//输入框为0
				if (str.length() == 0)
	            {
	            	pwd_weak.setBackgroundColor(Color.rgb(205,205,205));
	            	pwd_in.setBackgroundColor(Color.rgb(205,205,205));
	            	pwd_strong.setBackgroundColor(Color.rgb(205,205,205));
	            }
				//输入的纯数字为弱
				if (str.matches ("^[0-9]+$"))
	            {
	            	pwd_weak.setBackgroundColor(Color.rgb(255,129,128));
	            	pwd_in.setBackgroundColor(Color.rgb(205,205,205));
	            	pwd_strong.setBackgroundColor(Color.rgb(205,205,205));
	            }
				//输入的纯小写字母为弱
				else if (str.matches ("^[a-z]+$"))
	            {
	            	pwd_weak.setBackgroundColor(Color.rgb(255,129,128));
	            	pwd_in.setBackgroundColor(Color.rgb(205,205,205));
	            	pwd_strong.setBackgroundColor(Color.rgb(205,205,205));
	            }
				//输入的纯大写字母为弱
				else if (str.matches ("^[A-Z]+$"))
	            {
	            	pwd_weak.setBackgroundColor(Color.rgb(255,129,128));
	            	pwd_in.setBackgroundColor(Color.rgb(205,205,205));
	            	pwd_strong.setBackgroundColor(Color.rgb(205,205,205));
	            }	
				//输入的大写字母和数字,输入的字符小于7个密码为弱
				else if (str.matches ("^[A-Z0-9]{1,5}"))
	            {
					pwd_weak.setBackgroundColor(Color.rgb(255,129,128));
	            	pwd_in.setBackgroundColor(Color.rgb(205,205,205));
	            	pwd_strong.setBackgroundColor(Color.rgb(205,205,205));
	            }
				//输入的大写字母和数字,输入的字符大于7个密码为中
				else if (str.matches ("^[A-Z0-9]{6,16}"))
	            {
					pwd_weak.setBackgroundColor(Color.rgb(255,129,128));
	            	pwd_in.setBackgroundColor(Color.rgb(255,184,77));
	            	pwd_strong.setBackgroundColor(Color.rgb(205,205,205));
	            }
				//输入的小写字母和数字,输入的字符小于7个密码为弱
				else if (str.matches ("^[a-z0-9]{1,5}"))
	            {   
					pwd_weak.setBackgroundColor(Color.rgb(255,129,128));
	            	pwd_in.setBackgroundColor(Color.rgb(205,205,205));
	            	pwd_strong.setBackgroundColor(Color.rgb(205,205,205));
	            }	
				//输入的小写字母和数字,输入的字符大于7个密码为中
				else if (str.matches ("^[a-z0-9]{6,16}"))
	            {   
	            	pwd_weak.setBackgroundColor(Color.rgb(255,129,128));
	            	pwd_in.setBackgroundColor(Color.rgb(255,184,77));
	            	pwd_strong.setBackgroundColor(Color.rgb(205,205,205));
	            }	
				//输入的大写字母和小写字母,输入的字符小于7个密码为弱
				else if (str.matches ("^[A-Za-z]{1,5}"))
	            {
					pwd_weak.setBackgroundColor(Color.rgb(255,129,128));
	            	pwd_in.setBackgroundColor(Color.rgb(205,205,205));
	            	pwd_strong.setBackgroundColor(Color.rgb(205,205,205));
	            }
				//输入的大写字母和小写字母,输入的字符大于7个密码为中
				else if (str.matches ("^[A-Za-z]{6,16}"))
	            {
	            	pwd_weak.setBackgroundColor(Color.rgb(255,129,128));
	            	pwd_in.setBackgroundColor(Color.rgb(255,184,77));
	            	pwd_strong.setBackgroundColor(Color.rgb(205,205,205));
	            }
				//输入的大写字母和小写字母和数字,输入的字符小于5个个密码为弱
				else if (str.matches ("^[A-Za-z0-9]{1,5}"))
	            {
					pwd_weak.setBackgroundColor(Color.rgb(255,129,128));
	            	pwd_in.setBackgroundColor(Color.rgb(205,205,205));
	            	pwd_strong.setBackgroundColor(Color.rgb(205,205,205));
	            }
				//输入的大写字母和小写字母和数字,输入的字符大于6个个密码为中
				else if (str.matches ("^[A-Za-z0-9]{6,8}"))
	            {
					pwd_weak.setBackgroundColor(Color.rgb(255,129,128));
	            	pwd_in.setBackgroundColor(Color.rgb(255,184,77));
	            	pwd_strong.setBackgroundColor(Color.rgb(205,205,205));
	            }
				//输入的大写字母和小写字母和数字,输入的字符大于8个密码为强
				else if (str.matches ("^[A-Za-z0-9]{9,16}"))
	            {
	            	pwd_weak.setBackgroundColor(Color.rgb(255,129,128));
	            	pwd_in.setBackgroundColor(Color.rgb(255,184,77));
	            	pwd_strong.setBackgroundColor(Color.rgb(113,198,14));
	            }
	            	    
			}

			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {	

			}

			public void afterTextChanged(Editable s) {

			}
		});


源码传送:http://download.csdn.net/detail/wj198524/9778821


  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值