IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_debug_changepass]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_debug_changepass]
GO
-- =============================================
-- Author:<Author,,Name>
-- Create date: <Create Date,,>
-- Description:<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[mps_debug_changepass](@cuaccount nvarchar(50),@newpass varchar(400),@isreset int=0)
AS
BEGIN
SET NOCOUNT ON;
declare @oldpass varchar(400)
select @oldpass = cu_pass from mps_login where cu_account = @cuaccount
if(@isreset = 0)
begin
select @newpass = cp_old from mps_changedpass_history 
where cp_id = (select max(cp_id) from mps_changedpass_history where cp_account = @cuaccount)
update mps_login set cu_pass = @newpass where cu_account = @cuaccount
if exists(select 1 from mps_changedpass_history where cp_account = @cuaccount)
begin
update mps_changedpass_history 
set cp_new = @newpass
where cp_account = @cuaccount
end
else
begin
insert into mps_changedpass_history(cp_account,cp_old,cp_new,cp_date)
values(@cuaccount,@oldpass,@newpass,GETDATE())
end
end
else
begin
update mps_login 
set cu_pass = substring(sys.fn_sqlvarbasetostr(HashBytes('MD5',@newpass)),3,32) 
where cu_account = @cuaccount
if exists(select 1 from mps_changedpass_history where cp_account = @cuaccount)
begin
update mps_changedpass_history 
set cp_new = substring(sys.fn_sqlvarbasetostr(HashBytes('MD5',@newpass)),3,32)
where cp_account = @cuaccount
end
else
begin
insert into mps_changedpass_history(cp_account,cp_old,cp_new,cp_date)
values(@cuaccount,@oldpass,substring(sys.fn_sqlvarbasetostr(HashBytes('MD5',@newpass)),3,32),GETDATE())
end
end
SET NOCOUNT OFF
END