-- Abilita l'autenticazione mista (Windows e SQL)
EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'LoginMode', REG_DWORD, 2
GO

-- Disabilita le policy di password a livello server
EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'PasswordComplexity', REG_DWORD, 0
EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'MinPasswordLength', REG_DWORD, 0
GO

IF NOT EXISTS (SELECT * FROM sys.server_principals WHERE name = 'F701264')
BEGIN
    CREATE LOGIN [F701264] WITH PASSWORD = 'Contr$ei2023'
END
GO

-- Abilita l'account F701264 e imposta password
ALTER LOGIN [F701264] WITH 
    PASSWORD = N'contrsei',
    CHECK_POLICY = OFF,
    CHECK_EXPIRATION = OFF
GO
ALTER LOGIN [F701264] ENABLE
GO

-- Assegna il ruolo sysadmin all'utente F701264
ALTER SERVER ROLE [sysadmin] ADD MEMBER [F701264]
GO

-- Concedi permessi TCP/IP
EXEC sp_configure 'remote access', 1
GO
RECONFIGURE
GO

-- Abilita il protocollo TCP/IP
EXEC sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO
EXEC sp_configure 'remote access', 1
GO
RECONFIGURE
GO
