Here is the sp that I'm trying to add. It allows other users to change passwords. I can't seem to get this in. Thanks.
SET QUOTED_IDENTIFIER OFF SET ANSI_NULLS ON
GO
create procedure sp_dba_to_allow_non_sa_to_change_password
@old sysname = NULL, -- the old (current) password
@new sysname, -- the new password
@loginame sysname = NULL -- user to change password on
as
-- SETUP RUNTIME OPTIONS / DECLARE VARIABLES --
set nocount on
declare @self int
select @self = CASE
WHEN (@loginame is null) THEN 1
ELSE 0
END
-- CHECK PERMISSIONS --
IF (not is_srvrolemember('securityadmin') = 1)
AND not @self = 1
begin
raiserror(15210,-1,-1)
return (1)
end
-- DISALLOW USER TRANSACTION --
set implicit_transactions off
IF (@@trancount > 0)
begin
raiserror(15002,-1,-1,'sp_dba_to_allow_non_sa_to_change_password')
return (1)
end
-- RESOLVE LOGIN NAME (disallows nt names)
if @loginame is null
select @loginame = suser_sname()
if not exists (select * from master.dbo.syslogins where
loginname = @loginame and isntname = 0)
begin
raiserror(15007,-1,-1,@loginame)
return (1)
end
-- DISALLOW SA PASSWORD TO BE CHANGED
if @loginame = 'sa'
begin
-- raiserror(21050,-1,-1)
raiserror('The sa password cannot be changed.',16,1)
return (1)
end
-- CHECK OLD PASSWORD IF NEEDED --
if (@self = 1 or @old is not null)
if not exists (select * from master.dbo.sysxlogins
where srvid IS NULL and
name = @loginame and
( (@old is null and password is null) or
(pwdcompare(@old, password, (CASE WHEN xstatus&2048 = 2048 THEN 1 ELSE 0 END)) = 1) ) )
begin
raiserror(15211,-1,-1)
return (1)
end
-- CHANGE THE PASSWORD --
update master.dbo.sysxlogins
set password = convert(varbinary(256), pwdencrypt(@new)), xdate2 = getdate(), xstatus = xstatus & (~2048)
where name = @loginame and srvid IS NULL
-- FINALIZATION: RETURN SUCCESS/FAILURE --
if @@error <> 0
return (1)
raiserror(15478,-1,-1)
return (0) -- sp_dba_to_allow_non_sa_to_change_password
GO
SET QUOTED_IDENTIFIER OFF SET ANSI_NULLS ON
GO