SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[cs_users_BackPort]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[cs_users_BackPort]
GO




CREATE proc [dbo].cs_users_BackPort
(
	@SettingsID int,
	@UserName nvarchar(256),
	@Password nvarchar(128) = null,
	@PasswordSalt nvarchar(128) = null,
	@PasswordFormat int = null
)
as
SET Transaction Isolation Level Read UNCOMMITTED
if(@Password is null)
Begin
	Select a.Password, a.PasswordSalt, a.PasswordFormat  FROM cs_vw_Users_FullUser c, aspnet_Membership a where a.UserId = c.UserId and SettingsID = @SettingsID and @UserName = UserName
End
Else
Begin
	Declare @UserID uniqueidentifier
	Select @UserID = UserId FROM cs_vw_Users_FullUser where UserName = @UserName and SettingsID = @SettingsID
	
	Update aspnet_Membership
	Set Password = @Password, PasswordSalt = @PasswordSalt, PasswordFormat = @PasswordFormat
	Where UserId = @UserID
		
End

go


grant execute on [dbo].[cs_users_BackPort] to public
go