修改密码主要代码:db.execSQL("update user set passward = ? where username = ?",new String[] { updata_newpass, updata_user });
修改密码功能全部代码:
代码语言:txt复制// 修改密码确定
updata_newpass = et_updata_newpass.getText().toString();// 新密码
updata_oldpass = et_updata_oldpass.getText().toString();// 新密码
updata_user = et_updata_user.getText().toString();// 新密码
Cursor cursor_getuser = db.rawQuery(
"select * from user where username = ?",
new String[] { updata_user });// 新建数据库指针
if (updata_user.equals("")) {// 用户名为空
DiyToast.showToast(LoginActivity.this, "请输入用户名");
} else if (updata_oldpass.equals("")) {// 旧密码为空
DiyToast.showToast(LoginActivity.this, "请输入旧密码");
} else if (updata_newpass.equals("")) {// 新密码为空
DiyToast.showToast(LoginActivity.this, "请输入新密码");
} else {
if (cursor_getuser.moveToNext()) {
Cursor cursor_getoldpass = db.rawQuery(
"select * from user where username = ?",
new String[] { updata_user });
cursor_getoldpass.moveToFirst();
String oldpass = cursor_getoldpass
.getString(cursor_getoldpass
.getColumnIndex("passward"));
if (updata_oldpass.equals(oldpass)) {
if (updata_newpass.equals(updata_oldpass)) {
DiyToast.showToast(LoginActivity.this, "新旧密码不能一致!");
} else {
db.execSQL(
"update user set passward = ? where username = ?",
new String[] { updata_newpass, updata_user });// 更新数据库
DiyToast.showToast(LoginActivity.this, "修改密码成功");
line_login.setVisibility(View.VISIBLE);
line_reg.setVisibility(View.GONE);
line_updata_pass.setVisibility(View.GONE);
}
} else {
DiyToast.showToast(LoginActivity.this, "旧密码输入错误");
}
} else {
DiyToast.showToast(LoginActivity.this, "用户名错误");
}
}