极其容易!!!为什么改不了密码????(20分)

  • 主题发起人 主题发起人 evenzaj
  • 开始时间 开始时间
E

evenzaj

Unregistered / Unconfirmed
GUEST, unregistred user!
var
asql:string;
begin
if trim(edit1.Text)='' then
begin
messagedlg('请输入新密码!',mtinformation,[mbok],0);
edit1.SetFocus;
end
else
if trim(edit2.Text)='' then
begin
messagedlg('请确认新密码!',mtinformation,[mbok],0);
edit2.SetFocus;
end
else
if trim(edit1.Text)<>trim(edit2.Text) then
begin
messagedlg('两次输入结果不一致!',mterror,[mbok],0) ;
edit1.SetFocus;
end
else
begin
close;
query1.sql.clear;
asql:=' update passcheck set password='''+(passwordchangefrm.Edit1.Text)+''' where username='''+trim(loginfrm.ComboBox1.Text )+'''';
query1.SQL.Text:=asql;
try
query1.ExecSQL;
messagedlg('密码修改成功!请记住新密码.',mtinformation,[mbok],0);
edit1.Clear;
edit2.Clear;
edit1.SetFocus;
passwordchangefrm.Hide;
except
messagedlg('密码修改失败!',mtinformation,[mbok],0);
abort;
end;
end;
end;

各位我几乎没有分了,但有问题要问,所以就简单的问题,就少些,原谅!!!
 
query1.close; //!!!
query1.sql.clear;
asql:=' update passcheck set password='''+(passwordchangefrm.Edit1.Text)+''' where username='''+trim(loginfrm.ComboBox1.Text )+'''';
query1.SQL.Text:=asql;
try
query1.ExecSQL;
messagedlg('密码修改成功!请记住新密码.',mtinformation,[mbok],0);
edit1.Clear;
edit2.Clear;
edit1.SetFocus;
passwordchangefrm.Hide;
except
messagedlg('密码修改失败!',mtinformation,[mbok],0);
abort;
end;
end;
end;
 
query1.close
query1.sql.clear;
query1.sql.add(' update passcheck set password="'+(passwordchangefrm.Edit1.Text)+'" where username='''+trim(loginfrm.ComboBox1.Text )+'"');
 
query1.close
query1.sql.clear;
query1.sql.add('update passcheck set password='+''''+passwordchangefrm.Edit1.Text+''''+'where username='+''''+trim(loginfrm.ComboBox1.Text )+'''';;
 
关注,次问题没有解决!
 
有什么有没有发生异常
或出现提示信息
如果程序正常执行
有可能是sql 的条件有问题
where username='''+trim(loginfrm.ComboBox1.Text )+'''' //????

可能是没有找到匹配的记录 ********


我建义你用参数的query


 
query1.sql.add('update passcheck set password='+#39+passwordchangefrm.Edit1.Text+#39+' where username='+#39+trim(loginfrm.ComboBox1.Text )+#39;

+' where
不能+'where:
为什么?呵呵,不用解释吧
 
asql:=' update passcheck set password=:p_password where username=:p_username'
parameters.paremebyanem('p_password').value:=passwordchangefrm.Edit1.Text
parameters.paremebyanem('p_username').value:=trim(loginfrm.ComboBox1.Text )
 
各位,我看了一下SQL 数据库,好象输入的密码都是和用户名没有对应起来,都是另外开一行
来输入的。没有改到密码!

比如 username password
administrator 123
输入新更改密码后,变这样了
username password
administrator 123
1234
1234和原来的123根本没有联系起来,很奇怪!
 
你用SQL Monitor或数据库的监视器跟一下吧,问题好象不在Update语句
 
强烈关注了,用时间探查器,好象选择数据库后,一个表都没有出现!!
 
>时间探查器
????
 
password='''+(passwordchangefrm.Edit1.Text)+'''

需要用括号吗?
 
各位,我又重新做了一个表,但还是修改不了密码!
to cto-wind
是不用括号,但用了也没有错
 
排除语句的错误,如果passwordchangefrm,loginfrm当前不是在显示状态的话
是很有可能取不到值的,因为你的form已经free了,上面输入的值已经不存在了。
解决的办法是将输入的值存在该public段的的两个全局共用变量上,基它form在
调用那个变量。

不信你跟踪一下语句中的passwordchangefrm.Edit1.Text, loginfrm.ComboBox1.Text
十之八九是空值。
 
各位,我看了一下SQL 数据库,好象输入的密码都是和用户名没有对应起来,都是另外开一行
来输入的。没有改到密码!

比如 username password
administrator 123
输入新更改密码后,变这样了
username password
administrator 123
1234
1234和原来的123根本没有联系起来,很奇怪!

我也觉的是 cto-wind 那样, 看看 loginfrm.ComboBox1.Text 的值吧

 
有可能是你的用户名是为空没有登记。
我试了可以修改密码。
 
to coldew 你说的用户名没有登记,能具体点说出在哪里没有登记吗?
 
你看看我的是怎么做的,也许对你有帮助~!
edtname是用户名的TEdit控件,
edtoldpasswd是输入旧密码的TEdit控件,
edtnewpasswd是输入新密码的TEdit控件,
edtnewpasswd1是确认新密码的TEdit控件~!
procedure Tfrmmain.btnupdatepasswordClick(Sender: TObject);
var
ssql:string;
begin
if edtoldpasswd.Text <> query1.FieldByName('password').Asstring then
begin
Application.MessageBox ('您输入的旧密码不正确,请重新输入!','提示信息',mb_ok or mb_iconinformation);
edtoldpasswd.Clear;
edtoldpasswd.SetFocus;
exit;
end;
if edtnewpasswd.Text <> edtnewpasswd1.Text then
begin
Application.MessageBox ('您输入的确认密码跟新密码不符,请重新输入!','提示信息',mb_ok or mb_iconinformation);
edtoldpasswd.Clear;
edtnewpasswd.Clear;
edtnewpasswd1.Clear;
edtoldpasswd.SetFocus;
exit;
end;
ssql := 'update dbo.users set passwd=' + #39 + edtnewpasswd.Text + #39 + 'where name=' + #39 +edtname.Text + #39;
query1.SQL.Clear;
query1.SQL.Add(ssql);
query1.ExecSQL;
ssql:='select * from dbo.tester where name=' + #39 +edtname.Text + #39 ;
query1.SQL.Clear;
query1.SQL.Add (ssql);
query1.qrylogin.Open;
edtoldpasswd.Clear;
edtnewpasswd.Clear;
edtnewpasswd1.Clear;
Application.MessageBox ('密码修改成功!','提示信息', mb_ok or mb_iconinformation);
end;
 
我的loginfrm
全部原代码:
unit loginform;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Db, DBTables, Buttons;

type
Tloginfrm = class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Query1: TQuery;
Database1: TDatabase;
ComboBox1: TComboBox;
procedure BitBtn2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
function openfrm:boolean;
private
{ Private declarations }
public
{ Public declarations }

end;

var
loginfrm: Tloginfrm;
LoginUser:String;
implementation

uses adminform, passwordchangeform, mainform, queryform, operatorform;

{$R *.DFM}

procedure Tloginfrm.BitBtn2Click(Sender: TObject);
begin
application.Terminate ;
end;

procedure Tloginfrm.FormShow(Sender: TObject);
var
i :integer;
begin
with query1 do
begin
sql.Text:='select distinct username from passcheck';
open;
comboBox1.Items.Clear;
for i:=1 to recordcount do
begin
comboBox1.Items.Add(fieldbyname('username').asstring);
next;
end;
close;
end;

end;

procedure Tloginfrm.BitBtn1Click(Sender: TObject);
var
a:string;
begin
with query1 do
begin
close;
sql.clear;
sql.Add('SELECT username,password FROM passcheck WHERE username=''' +COMBOBOX1.TEXT +'''');
open;
end;
if query1.eof then
begin
showmessage(' 无此用户!! ');
combobox1.SetFocus;
end
else
begin
a := edit1.text;
trim(a);
//a:=query1.fieldbyname('password').asstring;
LoginUser:=COMBOBOX1.Text;
if a <> query1.fieldbyname('password').asstring then
begin
showmessage(' 密码错误!!');
edit1.SetFocus;
end
else
MODALRESULT := mrok;
end;
end;

function tloginfrm.openfrm: boolean;
begin
if showModal = mrok then
result:=true
else
result:=false;
end;


procedure Tloginfrm.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key=chr(13) then
begin
key:=chr(0);
BitBtn1.click;
end;
end;
end.

我的passwordchangefrm全部原代码
unit passwordchangeform;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, Db, DBTables;

type
Tpasswordchangefrm = class(TForm)
Label1: TLabel;
Label2: TLabel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Query1: TQuery;
Database1: TDatabase;
Edit1: TEdit;
Edit2: TEdit;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure Edit2KeyPress(Sender: TObject; var Key: Char);

private
{ Private declarations }
public
{ Public declarations }

end;

var
passwordchangefrm: Tpasswordchangefrm;

implementation

uses loginform;

{$R *.DFM}

procedure Tpasswordchangefrm.BitBtn1Click(Sender: TObject);
var
asql:string;
begin
if trim(edit1.Text)='' then
begin
messagedlg('请输入新密码!',mtinformation,[mbok],0);
edit1.SetFocus;
end
else
if trim(edit2.Text)='' then
begin
messagedlg('请确认新密码!',mtinformation,[mbok],0);
edit2.SetFocus;
end
else
if trim(edit1.Text)<>trim(edit2.Text) then
begin
messagedlg('两次输入结果不一致!',mterror,[mbok],0);
edit1.SetFocus;
end
else
begin
query1.Close;
query1.sql.clear;
asql:='update passcheck set password='+#39+edit1.Text+#39+' where username='+#39+loginfrm.ComboBox1.Text+#39;
query1.SQL.Text:=asql;

try
query1.ExecSQL;
messagedlg('密码修改成功!请记住新密码.',mtinformation,[mbok],0);
edit1.Clear;
edit2.Clear;
passwordchangefrm.Hide;
query1.Close;
except
messagedlg('密码修改失败!',mtinformation,[mbok],0);
abort;
end;
end;
end;

procedure Tpasswordchangefrm.BitBtn2Click(Sender: TObject);
begin
self.Close;
end;

procedure Tpasswordchangefrm.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
if key=chr(13) then
begin
key:=chr(0);
BitBtn1.click;
end;
end;
end.

我的工程(project)的全部代码:
program mycar;

uses
Forms,
mainform in 'mainform.pas' {mainfrm},
loginform in 'loginform.pas' {loginfrm},
passwordchangeform in 'passwordchangeform.pas' {passwordchangefrm},
carqueryform in 'carqueryform.pas' {carqueryfrm},
company_query in 'company_query.pas' {companyqueryfrm},
weihuform in 'weihuform.pas' {weihufrm},
type_query in 'type_query.pas' {typequeryfrm},
pai_query in 'pai_query.pas' {paiqueryfrm},
nianshen_query in 'nianshen_query.pas' {nianshenqueryfrm},
usedate_query in 'usedate_query.pas' {usedatequeryfrm},
baofei_query in 'baofei_query.pas' {baifeiqueryfrm},
operatorform in 'operatorform.pas' {operatorfrm},
queryform in 'queryform.pas' {queryfrm},
cheliangxiuli_frm1 in 'E:/canproject/cheliangxiuli_frm1.pas' {cheliangxiuli_frm},
cheliangluru_frm1 in 'cheliangluru_frm1.pas' {cheliangluru_frm},
operator_add in 'operator_add.pas' {operatoraddfrm},
cheliang_add1 in 'cheliang_add1.pas' {cheliang_add},
report_companyform in 'report_companyform.pas' {report_companyfrm: TQuickRep},
report_typeform in 'report_typeform.pas' {report_typefrm: TQuickRep},
report_paiform in 'report_paiform.pas' {report_paifrm: TQuickRep},
report_nianfenform in 'report_nianfenform.pas' {report_nianfenfrm: TQuickRep},
report_nianshenform in 'report_nianshenform.pas' {report_nianshenfrm: TQuickRep},
report_baofeiform in 'report_baofeiform.pas' {report_baofeifrm: TQuickRep};

{$R *.RES}
begin
Application.Initialize;
Application.CreateForm(Tloginfrm, loginfrm);
if loginfrm.openfrm then
begin
loginfrm.free;
if loginuser='administrator' then
Application.CreateForm(Tmainfrm,mainfrm);
if Loginuser='operator' then
Application.CreateForm(Toperatorfrm, operatorfrm);
if loginuser='user' then
Application.CreateForm(Tcarqueryfrm, carqueryfrm);
Application.CreateForm(Tpasswordchangefrm, passwordchangefrm);
Application.CreateForm(Tcarqueryfrm, carqueryfrm);
Application.CreateForm(Tcompanyqueryfrm, companyqueryfrm);
Application.CreateForm(Tweihufrm, weihufrm);
Application.CreateForm(Ttypequeryfrm, typequeryfrm);
Application.CreateForm(Tpaiqueryfrm, paiqueryfrm);
Application.CreateForm(Tnianshenqueryfrm, nianshenqueryfrm);
Application.CreateForm(Tusedatequeryfrm, usedatequeryfrm);
Application.CreateForm(Tbaifeiqueryfrm, baifeiqueryfrm);
Application.CreateForm(Tcheliangxiuli_frm, cheliangxiuli_frm);
Application.CreateForm(Tcheliangluru_frm, cheliangluru_frm);
Application.CreateForm(Toperatoraddfrm, operatoraddfrm);
Application.CreateForm(Tcheliang_add, cheliang_add);
Application.CreateForm(Treport_companyfrm, report_companyfrm);
Application.CreateForm(Treport_typefrm, report_typefrm);
Application.CreateForm(Treport_paifrm, report_paifrm);
Application.CreateForm(Treport_nianfenfrm, report_nianfenfrm);
Application.CreateForm(Treport_nianshenfrm, report_nianshenfrm);
Application.CreateForm(Treport_baofeifrm, report_baofeifrm);
Application.Run;
end;
end.
 
后退
顶部