0

我有两个名为 security_questions 和 login 的表。登录表中的列是:

Username, Security_QA_ID, Security_Answer, Security_Attempts,Last_Login,Password_Attempts

其中 security_questions 有:

ID, Name

其中 Security_QA_ID 用 ID 引用

CREATE DEFINER=`satish`@`%` PROCEDURE `p_chkAnswer`(
IN sq VARCHAR(75),
IN sa VARCHAR(20) ,
IN uname VARCHAR(15) ,
out msg INT
)
BEGIN
select (COUNT(*) > 0) INTO @result from login join security_questions on Security_QA_ID = ID where User_Name=uname and Name=sq and Security_Answer=sa;
set msg = @result;
if @result = 1 Then
UPDATE login SET  Last_Login=now(),Password_Attempts=0 where User_Name=uname;
else
UPDATE login SET  Security_Attempts=Security_Attempts+1 where User_Name=uname;
End if;

END 

但在每次只有 else 部分执行。提前致谢

4

1 回答 1

0

您的代码非常混乱且难以阅读(至少对我而言),我将您的语句简化为单个 SELECT 以便我可以检查您的选择是否正确,并且看起来是正确的:

CREATE TABLE `login`
 ( User_Name text, 
   Security_QA_ID int(11),
   Security_Answer text,
   Security_Attempts datetime,
   Last_Login datetime,
   Password_Attempts int(11)
 );

CREATE TABLE `security_questions`
 (ID int(11), 
  Name text
  );

INSERT INTO login SET
 User_name = 'a',
 Security_QA_ID = 1,
 Security_Answer = 'c',
 Security_Attempts = NOW(),
 Last_Login = NOW(),
 Password_Attempts = 0;

INSERT INTO security_questions SET
 ID = 1,
 Name = 'b';

和选择

SELECT IF(COUNT(*) > 0, 1, 0) AS Authenticated
from (login)
LEFT join security_questions on Security_QA_ID = ID 
where User_Name='a' and Name='b' and Security_Answer='c'

你必须使用这个DEFINER吗?编写 PHP/Perl/etc 代码来检查Authenticated是否非零不是更容易吗?

于 2013-07-01T09:54:15.790 回答