使用QT和SQLITE DB忘记密码功能

发布于 2025-02-03 06:59:45 字数 187 浏览 2 评论 0原文

我正在尝试使用SQLite数据库在QT中构建​​登录屏幕。我已经成功实现了注册并登录功能,并且也想添加“忘记密码”功能。用户应输入他的电子邮件&他在注册时使用的电话号码,如果在DB中找到该号码,则用户可以设置新密码。问题是我不明白我应该用什么功能用该电子邮件& amp;电话号码来替换用户密码。如何通过代码选择DB中的正确行。谢谢您的任何帮助!

I'm trying to build my login screen in QT using SQLITE database. I've already successfully implemented sign up and log in features and I'd like to add "Forgot password" feature as well. The user should input his email & phone number he used while signing up and if it was found in db then the user can set a new password. The problem is that I don't understand what function I should use to replace a user's password with exactly that email&phone number. How to select the right row in the db through the code. Thank you for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里的微风 2025-02-10 06:59:45

(我认为您需要密码恢复过程,而不是“如何查询记录”。如果您需要数据级别的帮助,我们也需要表结构)

这是我一段时间以前的一个客户的工作方式。如果您需要更多澄清,请发表评论。

  1. 使用2因子身份验证。
  2. 通过API(如果存在)验证电子邮件或电话#,
  3. 然后将OTP发送到该手机#或用户选择的电子邮件地址。
    (我使用DB函数为我的需求生成OTP,以下我为您的参考附加了该代码)
  4. 最好将TTL(时间离开)值分配给该OTP,以在一段时间后将其删除。

我将为您提供一个示例过程,我前一段时间用于同样的目的。

示例表和DB函数(Postgres DB)

CREATE TABLE myf_t_otp (
    otp_id bigserial NOT NULL,
    otp_category int8 NOT NULL,
    otp_otp varchar(60) NOT NULL,
    otp_user_name varchar(100) NULL,
    otp_user_id int8 NULL,
    otp_value varchar(100) NULL, 
    otp_code varchar(60) NULL,
    otp_code2 varchar(60) NULL,
    otp_description varchar(500) NULL,
    otp_active int8 NULL,
    otp_status int8 NULL,
    otp_country int8 NULL,
    otp_company int8 NULL,
    otp_department int8 NULL,
    created_by varchar(30) NULL,
    created_date timestamp NULL DEFAULT current_timestamp,
    last_modified_by varchar(30) NULL,
    last_modified_date timestamp NULL,
    CONSTRAINT myf_t_otp_pkey PRIMARY KEY (otp_id)
);

_OTP_CATEGORY ='Mobile'或'Web App'
_OTP_VALUE ='电子邮件或电话#'
_OTP_USER_NAME ='用户名'
其他参数是可选的

throgh此“ insandNum:= cast(random() * 100000 as int);”系统
将创建一个随机#并将其返回给用户。发送电子邮件和短信
通过Java应用程序进行管理

CREATE OR REPLACE FUNCTION myf_fun_otp(_otp_category bigint, _otp_value character varying, _otp_user_name character varying DEFAULT ''::character varying, _otp_user_id bigint DEFAULT '-1'::integer, _created_by character varying DEFAULT ''::character varying, _otp_description character varying DEFAULT ''::character varying, _otp_active bigint DEFAULT 1, _otp_status bigint DEFAULT 1, _otp_country bigint DEFAULT '-1'::integer, _otp_company bigint DEFAULT '-1'::integer)
 RETURNS bigint
 LANGUAGE plpgsql
AS $function$
declare
    intRandNum int4;
    strValue varchar(10);

begin
    
    -- Generate Random values for OTP
    intRandNum := cast(random() * 100000 as int);
    strValue = rpad(cast(intRandNum as varchar(100)), 5,'0');
    intRandNum := cast(strValue  as int);


    -- Reset the previoud OTP's if any and disable before new one
    update myf_t_otp set
        otp_active = 0
    where otp_value = _otp_value and otp_category = _otp_category;
    
    -- Insert the new OTP
    INSERT INTO myf_t_otp
    (otp_category, otp_otp, otp_user_name, otp_user_id, otp_value, otp_description, 
    otp_active, otp_status, otp_country, otp_company,
    created_by)
    VALUES(_otp_category, cast(intRandNum as varchar(60)), _otp_user_name, _otp_user_id, _otp_value, _otp_description, _otp_active, _otp_status,
    _otp_country, _otp_company, _created_by);

    return intRandNum;

 
END
$function$
;

(I assume that you required the password recovery process and not about "how to query a record". If you need data level help, we need the table structure as well)

This is how I did for one of my client some time ago. If you need more clarification, please comment.

  1. Use 2-factor authentication.
  2. Verify the email or phone # via an API,
  3. If Existing, then send an OTP to that phone # or to the email address selected by the user.
    (I used a DB function to generate the OTP for my requirement and below I attached that code for your reference)
  4. Better assign a TTL (Time to leave) value to that OTP to remove it after some time.

I'll provide you with a sample process that I used some time ago for the same kind of purpose.

Sample Screens

Sample Table and a DB function (Postgres DB)

CREATE TABLE myf_t_otp (
    otp_id bigserial NOT NULL,
    otp_category int8 NOT NULL,
    otp_otp varchar(60) NOT NULL,
    otp_user_name varchar(100) NULL,
    otp_user_id int8 NULL,
    otp_value varchar(100) NULL, 
    otp_code varchar(60) NULL,
    otp_code2 varchar(60) NULL,
    otp_description varchar(500) NULL,
    otp_active int8 NULL,
    otp_status int8 NULL,
    otp_country int8 NULL,
    otp_company int8 NULL,
    otp_department int8 NULL,
    created_by varchar(30) NULL,
    created_date timestamp NULL DEFAULT current_timestamp,
    last_modified_by varchar(30) NULL,
    last_modified_date timestamp NULL,
    CONSTRAINT myf_t_otp_pkey PRIMARY KEY (otp_id)
);

_otp_category = 'Mobile' or 'Web App'
_otp_value = 'email or Phone #'
_otp_user_name = 'User name'
other parameters are optional

Throgh this "intRandNum := cast(random() * 100000 as int);" system
will create a random # and return it to the user. Send email and SMS
manage through a JAVA application

CREATE OR REPLACE FUNCTION myf_fun_otp(_otp_category bigint, _otp_value character varying, _otp_user_name character varying DEFAULT ''::character varying, _otp_user_id bigint DEFAULT '-1'::integer, _created_by character varying DEFAULT ''::character varying, _otp_description character varying DEFAULT ''::character varying, _otp_active bigint DEFAULT 1, _otp_status bigint DEFAULT 1, _otp_country bigint DEFAULT '-1'::integer, _otp_company bigint DEFAULT '-1'::integer)
 RETURNS bigint
 LANGUAGE plpgsql
AS $function$
declare
    intRandNum int4;
    strValue varchar(10);

begin
    
    -- Generate Random values for OTP
    intRandNum := cast(random() * 100000 as int);
    strValue = rpad(cast(intRandNum as varchar(100)), 5,'0');
    intRandNum := cast(strValue  as int);


    -- Reset the previoud OTP's if any and disable before new one
    update myf_t_otp set
        otp_active = 0
    where otp_value = _otp_value and otp_category = _otp_category;
    
    -- Insert the new OTP
    INSERT INTO myf_t_otp
    (otp_category, otp_otp, otp_user_name, otp_user_id, otp_value, otp_description, 
    otp_active, otp_status, otp_country, otp_company,
    created_by)
    VALUES(_otp_category, cast(intRandNum as varchar(60)), _otp_user_name, _otp_user_id, _otp_value, _otp_description, _otp_active, _otp_status,
    _otp_country, _otp_company, _created_by);

    return intRandNum;

 
END
$function$
;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文