关于密码验证的问题(简单的)
string userstring
string txtusername,psword,password
string ls_sql
datastore li_datastore
int n,m
txtusername=trim(ddlb_name.text)//ddlb.name是一个输入用户名的控件
psword=trim(sle_pw.text)//sle_pw.text是一个密码的控件
if txtusername="" then
messagebox("警告","用户名不能为空")
ddlb_name.setfocus()
return
end if
li_datastore=create datastore
select count(*) into :n from user where userid=:txtusername;
if n=0 then
messagebox("警告","你不是本系统的合法用户")
ddlb_name.setfocus()
destroy li_datastore;
return
end if
password=li_datastore.getitemstring(1,"password")
if isnull(password) then
password=""
end if
if trim(password) <> trim(psword) then
messagebox("警告","你的口令有误,请重新输入!")
sle_pw.setfocus()
return
end if
userstring=ddlb_name.text
sqlca.logid=userstring
//初始化
setprofilestring("user.ini","server","username",userstring)//?????
destroy li_datastore;
select hosname
into :gs_topic
from hospital;
if gs_topic="" or isnull(gs_topic) then
gs_topic="未注册"
end if
gs_bottom="PB工作室!"
///注:这是我抄的书上的程序,有点看不懂,请大家指教。。
建了一个表名字是user,存贮用户名称userid和密码password,就是datastore是什么意思?有什么用??直接从数据库中读用户名的密码在验证不是更简单吗?
还有setprofilestring()是什么意思??
select count(*) into :n from user where userid=:txtusername;这句的意思是
判断数据库中有此用户名是把?那后来n=0是什么意思,如果数据库中没有的话是返回0还是n为空呢,我运行时老说 你的口令有误,请重新输入! 。。
怎么回事呀?
问题点数:50、回复次数:10Top
1 楼moqijun(百分比)回复于 2004-05-04 16:40:46 得分 10
datastore 是数据存储。
setprofilestring() 是向一个文本文件里写字符串,
如果没有用户的话n=0
上面的代码有问题,取不到密码。直接用select语句取得密码然后比较就可以了。
不要用datastore那么多事。Top
2 楼moqijun(百分比)回复于 2004-05-04 16:41:44 得分 0
如果书上一共就只有那些代码的话。那本书就不要看了。Top
3 楼cxwsoftware(方宇)回复于 2004-05-04 16:57:24 得分 0
同意楼上
来晚了,帮你顶!Top
4 楼xiaofei1984(逍飞)回复于 2004-05-04 17:18:46 得分 0
不用数据窗口连接数据库需要什么参数,比如只是在一个控件中需要取数据库中的数据,,
除了
// Profile hos
SQLCA.DBMS = "ODBC"
SQLCA.AutoCommit = False
SQLCA.DBParm = "ConnectString='DSN=hos;UID=;PWD='"
connect;
这些外,像这样能取到数据吗??
string txtusername,psword,password
select password into :password from user where userid=:txtusername;Top
5 楼pokemonFK(烟鬼)回复于 2004-05-04 20:52:09 得分 0
sureTop
6 楼852zxc(小强)回复于 2004-05-04 21:02:04 得分 0
我看你是菜鸟,我建议你转学java吧。Top
7 楼joelee520(卧薪尝胆)回复于 2004-05-04 22:15:00 得分 0
li_datastore 没有retrieve(),也没有在找到用户后过滤,怎么对啊Top
8 楼ding1984(爱她一生一世)回复于 2004-05-04 22:59:07 得分 20
楼上的楼上,你凭什么让人改学别的呀,谁不是从菜鸟走过来的。。
楼住看看是不是表名有没有用关键字或系统保留字等,没有的话应该能
不用数据窗口连接数据库需要什么参数,比如只是在一个控件中需要取数据库中的数据,,
除了
// Profile hos
SQLCA.DBMS = "ODBC"
SQLCA.AutoCommit = False
SQLCA.DBParm = "ConnectString='DSN=hos;UID=;PWD='"
connect;
这些外,像这样能取到数据吗??
string txtusername,psword,password
select password into :password from user where userid=:txtusername;
这样联上数据库的,我原来就犯过这样的错。。Top
9 楼Yzerman(♀欲望♂生活)回复于 2004-05-04 23:46:19 得分 20
我写的一段密码比较的代码
String ls_uid,ls_pwd,ls_name
If Trim(sle_uid.Text) <> "" Then
ls_uid = Trim(sle_uid.Text)
ls_pwd = sle_pwd.Text
SELECT user_id,
user_pw,
user_name,
user_pms
INTO :gs_uid,
:gs_pwd,
:gs_name,
:gs_pms
FROM user_info
WHERE user_id = :ls_uid
;
If SQLCA.SQLCode <> -1 Then
If SQLCA.SQLCode = 100 Then
MessageBox("注意","无此用户,请与系统管理员联系!",Exclamation!)
sle_pwd.Text = ""
sle_uid.SetFocus()
Return
Else
If uf_encrypt(ls_pwd) <> gs_pwd Then
MessageBox("注意","您输入的密码不正确,请重新输入!",Exclamation!)
sle_pwd.Text = ""
sle_pwd.SetFocus()
Return
Else
Open(w_mdi_main)
Close(Parent)
gdt_last_login = DateTime(Today(),Now())
UPDATE user_info
SET user_last_login = :gdt_last_login,
user_online = 1
WHERE user_info.user_id = :gs_uid
;
COMMIT;
End If
End If
Else
MessageBox("错误",SQLCA.SQLErrText,StopSign!)
Halt Close
Return
End If
Else
MessageBox("注意","请输入用户名!",Exclamation!)
sle_uid.SetFocus()
sle_pwd.Text = ""
Return
End IfTop
10 楼xiaofei1984(逍飞)回复于 2004-05-05 21:39:56 得分 0
谢谢大家的回答,,问题已解决,就此揭帖Top




