<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Security on Henrique Almeida</title><link>https://alencarinosql.com.br/en/tags/security/</link><description>Recent content in Security on Henrique Almeida</description><generator>Hugo -- gohugo.io</generator><language>en</language><lastBuildDate>Sat, 26 Jul 2025 12:00:00 -0300</lastBuildDate><atom:link href="https://alencarinosql.com.br/en/tags/security/index.xml" rel="self" type="application/rss+xml"/><item><title>SQL Server Logins</title><link>https://alencarinosql.com.br/en/p/logins-sql-server/</link><pubDate>Sat, 26 Jul 2025 12:00:00 -0300</pubDate><guid>https://alencarinosql.com.br/en/p/logins-sql-server/</guid><description>&lt;img src="https://alencarinosql.com.br/p/logins-sql-server/1.jpg" alt="Featured image of post SQL Server Logins" />&lt;h1 id="configuring-logins-in-sql-server">Configuring Logins in SQL Server
&lt;/h1>&lt;h2 id="introduction">Introduction
&lt;/h2>&lt;p>Configuring logins in SQL Server is one of the essential tasks for making sure access to the database is properly controlled. There are two main kinds of logins in SQL Server: SQL Server logins and Windows logins. In this post, we&amp;rsquo;ll look at how to set up both kinds of logins and go over recommended practices for managing user access.&lt;/p>
&lt;h2 id="1-creating-sql-server-logins">1. Creating SQL Server Logins
&lt;/h2>&lt;p>In SQL Server, you can create logins through Management Studio or with T-SQL. Let&amp;rsquo;s start with a basic example of how to create a SQL Server login:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">CREATE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">LOGIN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">NovoUsuario&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">WITH&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">PASSWORD&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;SenhaSegura123&amp;#39;&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>This command creates a login named &lt;code>NovoUsuario&lt;/code> with an associated password. After creating it, you need to grant permissions to this login. That&amp;rsquo;s done by associating it with a user account inside a specific database.&lt;/p>
&lt;h3 id="example-of-creating-a-login-with-password-expiration-settings">Example of creating a login with password expiration settings:
&lt;/h3>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">CREATE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">LOGIN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">NovoUsuario&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">WITH&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">PASSWORD&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;SenhaSegura123&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">CHECK_POLICY&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">ON&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">CHECK_EXPIRATION&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">ON&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>In this example, the password policy and password expiration are enabled, forcing the user to change the password after the set period.&lt;/p>
&lt;h2 id="2-creating-windows-logins">2. Creating Windows Logins
&lt;/h2>&lt;p>You can also create Windows-based logins, letting users access the database with their operating system credentials:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">CREATE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">LOGIN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">DOMINIO&lt;/span>&lt;span class="err">\&lt;/span>&lt;span class="n">Usuario&lt;/span>&lt;span class="p">]&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">FROM&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">WINDOWS&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>In this case, the login is created using the Windows account &lt;code>DOMINIO\Usuario&lt;/code>.&lt;/p>
&lt;h3 id="windows-logins-vs-sql-server-logins">Windows Logins vs SQL Server Logins
&lt;/h3>&lt;ul>
&lt;li>&lt;strong>SQL Server logins&lt;/strong>: Useful in scenarios where users aren&amp;rsquo;t part of a domain, or when you need authentication that is exclusive to SQL Server.&lt;/li>
&lt;li>&lt;strong>Windows logins&lt;/strong>: Recommended when domain security and user account administration are already handled at the operating system level.&lt;/li>
&lt;/ul>
&lt;h2 id="3-mapping-logins-to-databases">3. Mapping Logins to Databases
&lt;/h2>&lt;p>After creating the login, the next step is to map it to a database. That&amp;rsquo;s done by creating a database user for the login:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="n">USE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">MeuBancoDeDados&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">CREATE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">USER&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">NovoUsuario&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">FOR&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">LOGIN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">NovoUsuario&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>The command above creates a user in the &lt;code>MeuBancoDeDados&lt;/code> database mapped to the &lt;code>NovoUsuario&lt;/code> login.&lt;/p>
&lt;h3 id="example-of-mapping-a-windows-login">Example of mapping a Windows login:
&lt;/h3>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="n">USE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">MeuBancoDeDados&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">CREATE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">USER&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">DOMINIO&lt;/span>&lt;span class="err">\&lt;/span>&lt;span class="n">Usuario&lt;/span>&lt;span class="p">]&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">FOR&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">LOGIN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">DOMINIO&lt;/span>&lt;span class="err">\&lt;/span>&lt;span class="n">Usuario&lt;/span>&lt;span class="p">];&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h2 id="4-granting-permissions">4. Granting Permissions
&lt;/h2>&lt;p>After mapping the login to the database, you need to grant the required permissions. For example, to grant read and write permissions:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">GRANT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">SELECT&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">INSERT&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">UPDATE&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">DELETE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">ON&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">SCHEMA&lt;/span>&lt;span class="p">::&lt;/span>&lt;span class="n">dbo&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">TO&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">NovoUsuario&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>This gives the &lt;code>NovoUsuario&lt;/code> user read and write permissions on every table in the &lt;code>dbo&lt;/code> schema.&lt;/p>
&lt;h3 id="example-of-granting-permissions-to-windows-logins">Example of granting permissions to Windows logins:
&lt;/h3>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-sql" data-lang="sql">&lt;span class="line">&lt;span class="cl">&lt;span class="k">GRANT&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">EXECUTE&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">ON&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">SCHEMA&lt;/span>&lt;span class="p">::&lt;/span>&lt;span class="n">dbo&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">TO&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">DOMINIO&lt;/span>&lt;span class="err">\&lt;/span>&lt;span class="n">Usuario&lt;/span>&lt;span class="p">];&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>In this case, the Windows login &lt;code>[DOMINIO\Usuario]&lt;/code> gets permission to execute stored procedures in the &lt;code>dbo&lt;/code> schema.&lt;/p>
&lt;h2 id="5-security-considerations">5. Security Considerations
&lt;/h2>&lt;ul>
&lt;li>&lt;strong>Strong passwords&lt;/strong>: Always use strong passwords for SQL Server logins. Weak passwords are one of the main attack vectors.&lt;/li>
&lt;li>&lt;strong>Least privilege&lt;/strong>: Avoid logins with administrative permissions unless absolutely necessary. Follow the principle of &amp;ldquo;least privilege&amp;rdquo;.&lt;/li>
&lt;li>&lt;strong>Windows logins&lt;/strong>: Whenever possible, use Windows logins, because they take advantage of the operating system&amp;rsquo;s security and authentication controls.&lt;/li>
&lt;li>&lt;strong>Auditing&lt;/strong>: It&amp;rsquo;s important to set up security auditing to monitor login activity, such as failed login attempts and logins with elevated privileges.&lt;/li>
&lt;/ul>
&lt;p>&lt;img src="https://alencarinosql.com.br/p/logins-sql-server/1.jpg"
width="705"
height="634"
srcset="https://alencarinosql.com.br/p/logins-sql-server/1_hu_d822462eef30d608.jpg 480w, https://alencarinosql.com.br/p/logins-sql-server/1_hu_3a4b96745022e00c.jpg 1024w"
loading="lazy"
alt="SQL Server Logins Configuration"
class="gallery-image"
data-flex-grow="111"
data-flex-basis="266px"
>&lt;/p>
&lt;h2 id="conclusion">Conclusion
&lt;/h2>&lt;p>Configuring logins in SQL Server is a fundamental task for ensuring security and access control over your data. By creating the right logins and applying security best practices, such as strong passwords and minimal permissions, you protect your database environment against unauthorized access. It&amp;rsquo;s also important to review permissions regularly and make sure logins are kept up to date and in line with your organization&amp;rsquo;s security policies.&lt;/p></description></item></channel></rss>