In this part, we will try to understand each and everything related to logins. So let’s move ahead to explore SQL Server logins and if you missed Part 1 & Part 2 you can check them out on the following link:
Login
A login is simply a set of credentials to gain access to SQL Server that requires proper authentication.
Users need login to connect to SQL Server or we can say logins are associated to a user and the association is done by a Security Identifier (SID). We can create a login based on a Windows Authentication (like a domain user or a Windows domain group) or we can create a login with SQL Server Authentication.

You can refer to Abhishek Yadav’s article on “Logins and Users in SQL Server“ for more information in which he explained very well about SQL Server logins and users.
Properties of logins


Note 1: Here I want to emphasize what the difference is between sys.syslogins & sys.server_principals and it is very important to know that:
sys.syslogins: It is a compatibility view to support 2000 databases and hence not recommended for use from SQL Server 2005 onwards.
This includes logins that are Windows, certificate mapped, or SQL authentication based.
sys.server_principals: It is recommended to use this view from SQL Server 2005 onwards.
Apart from Windows, certificate mapped or SQL authentication based logins it also includes server role information.
Note 2: SQL Server logins enclosed in double hash signs (##) represent internal logins created from certificates. The installation process will create users like “##MS_PolicyEventProcessingLogin##”, so do not be surprised when you see them on SQL Server. It is very clear from Figure 3.

“0x01050000000000051500000094F29E736A3CA94F37C329CD7B540000” using sp_helplogins in a query window and in the Object Explorer also.
or

Figure 5: Showing output of sp_msloginmappings that also shows that “XYZ\yashwant.kumar” login is associated with the user “yashwant”.
Exploring More about Logins

The Login Properties page is divided into the following five sections:
1. General
When we open the General tab of the login properties page we can see the following information:


Figure 8: Querying sys.certificates

Figure 9: Querying sys.asymmetric_keys
Note: SQL Server suports three algorithms for asymmetric key encryption: RSA_512, RSA_1024 & RSA_2048.
We can see the credentials using sys.credentials view, for example:

Figure10: Querying sys.credentials view
2. Server Roles
Used to grant server-wide security privileges to a user. Figure 11 shows the various server roles available for various tasks. There are 9.



3. User Mapping
There are the following two further options available:
a. Users mapped to this login: In this we can specify that the specific login can access which database.

In this example, it is clear that login “ianrox” will be able to access the Adventureworks2008R2 database. Now here the question is whether “ianrox” can perform the tasks on the AdventureWorks2008R2 database. For this database roles are relevant.
b. Database role membership for “DatabaseXYZ”: in this section, we can specify the activities a login can perform. In the following screenshot, we provided the database role “db_backupoperator”. It means that “ianrox” can perform backup activity for the Advetureworks2008R2 database.
There are 10 database roles in SQL Server.

Database roles & their description: The table in Figure 16 describes the database roles.

Note: a public database role cannot be dropped.
4. Securable
Securables are the resources that we can assign permissions, either at the server level that includes resources like Endpoints, Logins, Server Roles and Databases or at database-level that includes resources like Users, Database Roles, Certificates and Schemas.
SQL Server has securable at Schema level also that are called schema scope securable. Tables, Views, Procedures and so on are example of a schema scope securable.

5. Status
In this page we can set the permission to connect to a database engine for login or we can enable/disable a login. But what is the difference between grant/deny and enable/disable login?
To check the differences I created the following four cases:

i. Select DENY and ENABLED login: When we select this combination we will get the error message “Login failed for user ‘yashrox’. (Microsoft SQL Server, Error: 18456)”.
ii. Select GRANT and DISABLED login: When we select this combination we will get the error message “Login failed for user ‘yashrox’. Reason: The account is disabled. (Microsoft SQL Server, Error: 18470)”.
iii. Select DENY and DISABLED login: When we select this combination we will get the same error message as in the second combination, “Login failed for user ‘yashrox’. Reason: The account is disabled. (Microsoft SQL Server, Error: 18470)”.
iv. Select GRANT and ENABLED login: It’s a default method when a login is created, from this combination we will successfully connect to a database when the right login name & password are provided.
From all these cases I concluded the following things:
You can check it with the third case where we take deny & disable but we get the error “Login failed for user ‘yashrox’. Reason: The account is disabled”. (Microsoft SQL Server, Error: 18470). It clearly shows that the first login is authenticated then connect SQL permission.
Conclusion
This is all about the SQL Server Logins that I tried to explain. I also tried to touch on each aspect of logins. After knowing these things about SQL Server Logins we can dig in more and get more information because when you go into depth you will find some more new things. I tried a lot to make this more interesting, I hope you liked it.
Not a member yet? Register now
Are you a member? Login now