在存储过程中验证用户的最简单方法? [英] Easiest way to validate user in stored procedure?

查看:46
本文介绍了在存储过程中验证用户的最简单方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个存储过程,它可以通过发送loginpassword 来检查登录尝试时他们是否是有效用户如果它们在数据库中匹配.有没有简单的方法可以做到这一点?

I need a stored procedure that can check to see if, on a login attempt, whether or not they are a valid user by sending the login and password to see if they match in the database. Is there a simple way to do this?

推荐答案

如果没有更多信息,我目前能提供的最好的是:

Without more information the best I can offer for the moment is:

CREATE STORED PROCEDURE CheckPassword
    @username VARCHAR(20),
    @password varchar(20)
AS
BEGIN

SET NOCOUNT ON

IF EXISTS(SELECT * FROM usertable WHERE username = @username AND password = @password)
    SELECT 'true' AS UserExists
ELSE
    SELECT 'false' AS UserExists

END

根据您的回复修改查询 - 这将返回字符串true"或false",如果您愿意,您可以分别用位值 1 和 0 替换它们.

Query amended based on your response - this will return the string 'true' or 'false' you could replace them with bit values 1 and 0 respectively if you prefer.

这篇关于在存储过程中验证用户的最简单方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆