我被指示设计一个表格,用户使用他们的用户名和给他们的特定PIN或密码登录。
每次PASSWORD使用次数计算且其使用限制为5次,3次后,PASSWORD或PIN将自动从数据库中删除。 我也已经了解了存储过程。 请帮我检查一下是否正确。
CREATE PROCEDURE [dbo].PinValidation
@Pin_no varchar(24),
@Reg_Num varchar(24),
@Session varchar(50),
@Tries INT,
@Program varchar(50)
AS
begin
SELECT Pin_no FROM PIN
WHERE Pin_no=@Pin_no
if @Reg_Num is not Null
BEGIN
IF NOT EXISTS (SELECT Reg_Num FROM PIN WHERE Reg_Num=@Reg_Num)
BEGIN
UPDATE PIN
SET Tries= Tries+1
WHERE Reg_Num=@Reg_Num--incrases the value of tries by 1 each time pin is used
SELECT @Tries[Tries]
end
ELSE
UPDATE PIN
SET Reg_num = @Reg_Num, P_Session=@Session, Tries=Tries+1, Program=@Program
Where Pin_no=@Pin_no --Updates database pin value for used pin on first usage
end
end
If @Tries is not Null
BEGIN
if NOT EXISTS (SELECT Pin_no FROM PIN WHERE Pin_no=@Pin_no)
BEGIN
DELETE FROM [PIN ]
WHERE (( [Tries] = 3))--Check the Amount of times pin has been used if >3 delete entire pin row
end
end
ELSE
BEGIN
SELECT -1
END
答案 0 :(得分:0)
将pin或pw存储为 String 或将其存储为具有2个比例的对象
public class pin {
private int tries;
private string pin;
}
然后每当您发现他们输入的引脚与DB中的引脚匹配后,您将1添加到pin.tries并检查它是否等于5或更大,如果是,则将其从数据库中删除。