Skip to content
WordsOnTech
  • Home
  • MS SQL Server
    • SSRS
    • Always ON
    • Failover Cluster
    • Performance Tuning
    • Replication
  • AWS
  • Azure
  • Scripts
  • About Us
  • Join Us

How to match passwords for SQL Logins

February 7, 2023February 4, 2023 by Nitin

Problem Scenario

Recently, a very interesting question was put to us by our client. He was getting ready for migration for few databases between two SQL instances with SQL 2012 as source and SQL 2019 as target SQL instance.

For this, he used sp_help_revlogin to copy logins from source to target few weeks back. Source and target SQL instances were both live and in production and before migrating next batch of DBs to target, he wanted to check if there is any possibility of having two SQL logins with same name on source and target and yet have different passwords.

Understanding concept

In order to find the solution, we should understand that whenever a SQL login is created using password, it is assigned a unique SID and then converted into a hexadecimal hash value as shown below:

This hash value generated is also unique which is done by a certain combination of SID and password using some function. To prove this, I created two SQL login with name testlogin1 and testlogin2 with same password as testlogin1. But hash password generated was totally different as shown in below screenshot:

Another way to check the login password value is to go to that particular login and generate create login script. I did that for both logins mentioned above and here also, the values were total different with a message “For security reasons the login is created disabled and with a random password.”

Random password generation

Solution

With all the concepts placed above, only possible solution that I could think of was comparing password Hash for each password. Since, in our case, customer used sp_help_revlogin to migrate logins, password hash was matching for each of them as same SID is migrated to target SQL instance.

The comparison can be done either by storing password hash (using table sys.sql_logins) into a table for each SQL instance and then comparing hash values using inner join. Please note, you will require a linked server from one server to another to do this.

Another way could be by using excel sheet.

Only difference I found was with SQL logins which were created separately on each instance. There password hash was different and same was highlighted to customer.

Let me know if you know any other way of comparing the passwords.

Happy Learning!
Post Views: 290

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on WhatsApp (Opens in new window) WhatsApp
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to print (Opens in new window) Print
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to share on Telegram (Opens in new window) Telegram
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Tumblr (Opens in new window) Tumblr

Like this:

Like Loading...
Categories MS SQL Server, SQL Server Security Tags MS SQL Server, Password comparison, Password Hash, sp_help_revlogin, SQL Login, SQL Security, SQL Server, SQL Server hacks
Fixed: SQL Server Query Performance Issue
SQL Server Error 229: The SELECT permission was denied on the object ‘databases’, database ‘mssqlsystemresource’, schema ‘sys’.

Recent Posts

  • Out of memory exception in SQL Server Management Studio (SSMS) while opening ‘restore database’ page March 7, 2024
  • Using Snapshot Replication for Schema Transfer/Refresh Only March 7, 2024
  • Cleanup Log-shipping configuration through TSQL March 7, 2024
  • Configure non-default PostgreSQL instance for automatic start on machine start in RHEL March 4, 2024
  • Código de error: 22903, texto: “Ya hay otra conexión ejecutando ‘sp_replcmds’ para la captura de datos modificados en la base de datos actual.” March 4, 2024

AlwaysOn Amazon Web Services AWS AWS CLI AWS EC2 CDC Cloud costs Commvault cost monitoring cost optimization AWS encrypted backup Encryption Error 912 error 3417 Error 15151 Error 20011 Error 22017 Error 22307 Error 22903 HIGH CPU USAGE High Memory Issue Index optimization Login Failed LogShipping MS SQL Server MS_SSISServerCleanupJob Ola Hallengren Performance Tuning PowerShell Replication Replication Jobs S3 script Security SQL Server SQL Server 2017 SQL server 2019 SQL Server Backup SQL Server hacks SSIS_hotfix_install TDE TLOG Backups TSQL wait statistics Wait types

© 2025 WordsOnTech • Built with GeneratePress
Go to mobile version
%d
    We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok