Encrypt/Decrypt password: differenze tra le versioni
Da Webmobili Wiki.
Nessun oggetto della modifica |
Nessun oggetto della modifica |
||
| (Una versione intermedia di uno stesso utente non è mostrata) | |||
| Riga 11: | Riga 11: | ||
) | ) | ||
INSERT INTO @tempCustomer VALUES ('utente | DECLARE @passphrase nvarchar(200) = 'culo-sale-culo-scende' | ||
INSERT INTO @tempCustomer VALUES ('utente',ENCRYPTBYPASSPHRASE(@passphrase, N'nel mezzo di una matita mi ritrovai in culo un cammino')) | |||
select * from @tempCustomer | select * from @tempCustomer | ||
SELECT [UserName], CONVERT (nvarchar(1000), DECRYPTBYPASSPHRASE( | SELECT [UserName], CONVERT (nvarchar(1000), DECRYPTBYPASSPHRASE(@passphrase,[Password])) | ||
from @tempCustomer | from @tempCustomer | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Versione attuale delle 15:36, 5 apr 2022
Usiamo due funzioni standard di SQL Server:
- ENCRYPTBYPASSPHRASE([Stringa per il sale],[password in chiaro])
- DECRYPTBYPASSPHRASE([Stringa per il sale],[password cifrata])
Esempio
DECLARE @tempCustomer table (
[UserName] VARCHAR(50),
[Password] VARBINARY(1000)
)
DECLARE @passphrase nvarchar(200) = 'culo-sale-culo-scende'
INSERT INTO @tempCustomer VALUES ('utente',ENCRYPTBYPASSPHRASE(@passphrase, N'nel mezzo di una matita mi ritrovai in culo un cammino'))
select * from @tempCustomer
SELECT [UserName], CONVERT (nvarchar(1000), DECRYPTBYPASSPHRASE(@passphrase,[Password]))
from @tempCustomer