﻿


-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date, ,>
-- Description:	<Description, ,>
-- =============================================
CREATE FUNCTION [dbo].[fis_admin_authenticate_byID]
(
	@useraccount_id varchar(10),
	@password nvarchar(20)
)
RETURNS @RET TABLE ( [useraccount_id] varchar(5), [auth] smallint, [name] nvarchar(100) null, [firstname] nvarchar(100) null, [email] varchar(255) NULL, [mobile] varchar(50) null, [functions] varchar(1000), [language] varchar(2), [fullname] nvarchar(255) null, [fullname_rev] nvarchar(255) null)
AS
BEGIN
	DECLARE @auth smallint = -1;
	DECLARE @name nvarchar(255), @mobile varchar(50), @functions varchar(1000) = '';

	IF EXISTS( SELECT 0
		FROM [dbo].[fis_useraccounts] as ua
		WHERE ua.[DateDeleted] is null AND ua.[DateDisabled] is null
			AND [useraccount_id] = @useraccount_id and ISNULL(@useraccount_id, '') <> ''
			AND CAST(DECRYPTBYKEY(ua.[password_enc]) as nvarchar(20)) = @password
			AND @password <> ''
			AND ua.[password_enc] is not null
		)
	BEGIN
		INSERT INTO @RET SELECT * FROM [dbo].[fis_admin_getUserAccount](@useraccount_id);
	END

	RETURN;

END