Compare a credential secret against a known value
5
votes
1
answer
949
views
Suppose I have a SQL Server [Credential](https://learn.microsoft.com/en-us/sql/t-sql/statements/create-credential-transact-sql?view=sql-server-ver16) saved in the database with a specific secret. I want to only modify the credential if the secret saved in the database is different from the actual secret.
Sometimes, an example is good, so take a look at this:
CREATE CREDENTIAL [MyCred]
WITH IDENTITY = N'DOMAIN\User'
, SECRET = N'some_password';
So, after the password for DOMAIN\User
is changed from some_password
to some_new_password
, I need to update the secret, but only if the stored value does not match. i.e. I don't want to blindly drop and recreate the credential.
With server principals, I can use the LOGINPROPERTY([login_name], 'PasswordHash')
function to get the hashed version of the encrypted password stored in the master database, but that doesn't seem to work for credentials.
Asked by Hannah Vernon
(70988 rep)
Jan 26, 2023, 08:38 PM
Last activity: Jan 26, 2023, 10:11 PM
Last activity: Jan 26, 2023, 10:11 PM