畢業設計(二十七)--- 修改密碼



頁面表單:

<input type="hidden" value="${user.id }" id="userid" />
		原始密碼:<input type="password" id="oldpwd" name="oldpwd" class="easyui-validatebox" data-options="required:true" /><br/>
		新密碼:<input type="password" id="newpwd" name="newpwd" class="easyui-validatebox" data-options="required:true"    /><br/>
		再次輸入密碼:<input type="password" id="renewpwd" name="renewpwd" class="easyui-validatebox"    data-options="required:true"
   οnblur="checkmima();"  /><br/>
		<input type="button" value="確認修改" οnclick="xiugaimima();" /><br/>
		<label id="result" style="color:red;"></label>

javascript : 

使用的dwr 調用後臺方法,  dwr 使用不再介紹

 function xiugaimima(){
	  var userid = document.getElementById("userid").value;
	  var oldmima = document.getElementById("oldpwd").value;
	  var newmima = document.getElementById("newpwd").value;
	  //console.info(oldmima+"--"+newmima+"--"+userid);
	  manager.xiugaimima(userid,oldmima,newmima, callback23);
	  
  }
  function callback23(data){
	  $('#result').html(data);
  }
  
	function checkmima(){
		var newmima = document.getElementById('newpwd').value;
		var renewmima = document.getElementById("renewpwd").value;
		if(newmima.length<6){
			alert("密碼過短");
			return false;
		}
		if(newmima!=renewmima){
			alert('兩次輸入密碼不一致');
		}
		
	}

修改密碼的方法:

	public String xiugaimima(int uid, String pwd, String repwd) {
//		System.out.println(uid);
//		System.out.println(pwd);
//		System.out.println(repwd);
		Users u = this.findOneUsers(uid);
		MD5 md5 = new MD5(pwd);
		String yanzhengmm = md5.compute();
		// checkUser(u);密碼正確返回id 錯誤返回負數
		if (!u.getPassword().equals(yanzhengmm)) {
			return "原始密碼輸入錯誤";
		}
		MD5 md2 = new MD5(repwd);
		String ppp = md2.compute();
		u.setPassword(ppp);

		return "密碼修改成功";
	}




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章