octothorpe
Programmer
I'm hoping there is a way to verify a user's password (SQL Server account) within SQL without logging in as that user. Instead, I'd like to connect with a pre-established application account (to take maximum advantage of connection pooling), then impersonate the user.
Example:
Is there any way to check the supplied credentials that would work with this method? Note that in the scenario I'm dealing with, all users will have a SQL login; Windows logins are not a concern.
Any assistance is appreciated.
Example:
Code:
declare @user varchar(20)
declare @password varchar(20)
set @user = 'test'
set @password = 'goofball'
declare @token varbinary(100)
declare @disabled int
declare @authenticated int
set @disabled = ( select [is_disabled] from sys.server_principals where [sid] = suser_sid( @user ) )
-- ********* PERFORM USER/PASSWORD CHECK HERE *********
set @authenticated = 1
if ( @disabled = 0 and @authenticated = 1 )
begin
execute as user = @user with cookie into @token
-- do some stuff as that user
select suser_name() + ' did some stuff.'
revert with cookie = @token
end
else begin select 'failure!'end
Is there any way to check the supplied credentials that would work with this method? Note that in the scenario I'm dealing with, all users will have a SQL login; Windows logins are not a concern.
Any assistance is appreciated.