前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >使用数据库完成简单的修改密码功能

使用数据库完成简单的修改密码功能

作者头像
奶油话梅糖
发布2025-03-03 14:25:30
发布2025-03-03 14:25:30
7300
代码可运行
举报
运行总次数:0
代码可运行

本文编写于 199 天前,最后修改于 165 天前,其中某些信息可能已经过时。

修改密码主要代码:db.execSQL("update user set passward = ? where username = ?",new String[] { updata_newpass, updata_user }); 修改密码功能全部代码:

代码语言:javascript
代码运行次数:0
复制
// 修改密码确定
            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, "用户名错误");
                }
            }
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2025-03-03,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档