How to compare ms sql hashbytes results within vb6

Posted on 2016-11-06
Last Modified: 2016-11-09
We are using ms sql hashbytes to encrypt a password column.  What would be the best way to retrieve the value, compare and give the correct results to the user?  In ssms we can 'IF HASHBYTES('SHA1','ExpertExchange') = HASHBYTES('SHA1',@SuppliedPassword) ', but how can we do this compare within vb6? vb6 has an equivalent to hashbyte function?
Question by:rayluvs
  • 3

Author Comment

ID: 41876283

found this vb code to see how to incorporate what want.

Works fine for Hash ansi & unicode but not for sha1, it gies an error on 'SHA1Hash.HashFile' like it doesn't exist (see pix below)

How do we get file?
Do we need it?
Does the apps return the same value as SQL HASHBYTE function (see below example)?

SELECT HASHBYTES('SHA1', 'ExpertExchange')


(see code attached)
LVL 33

Expert Comment

ID: 41876715
How do we get file?
Depends on your application.

Do we need it?
Depends on your application.

Does the apps return the same value as SQL HASHBYTE function (see below example)?
Maybe, the image does not show any hash handling.

p.s. IF HASHBYTES('SHA1','ExpertExchange') = HASHBYTES('SHA1',@SuppliedPassword) is nonsense. Don't store passwords. It's insecure by design. Store a salted hash instead of it.
LVL 23

Accepted Solution

Pawan Kumar earned 500 total points
ID: 41876717
So if it working in SSMS then you can create a stored Procedure with a Parameter called User Name call that from VB code.


CREATE PROC CheckPwduser
	@SuppliedPassword VARCHAR(100)

	IF HASHBYTES('SHA1','ExpertExchange') = HASHBYTES('SHA1',@SuppliedPassword) 
			SELECT 1 as Output
			SELECT 0  as Output


Open in new window

So if you get value 0 then you have invalid password other wise valid password.

Hope it helps !

Author Comment

ID: 41876741

"p.s. IF HASHBYTES('SHA1','ExpertExchange') = HASHBYTES('SHA1',@SuppliedPassword) is nonsense. Don't store passwords. "

We placed this for references since we started are working with HASHBYTES function SQL and wanted to know how to do it in vb6.

"How do we get file?
Depends on your application."

The apps is not ours, we found it  and ran and it gave us that message, so we thought an expert can assist on the message

"Do we need it?
Depends on your application."

Same answer, we thought that by showing he code to EE, it would help helping us; again, it's not our code.

Can you take a look at the code? (maybe you can detect the problem)

"Store a salted hash instead of it."

Please provide an example of the process.

Pawan Kumar Khowal,

Thanx, if working in SSMS that would be great, however we are working with vb6 (unless we can pass the users password to SQL and compre and return the resulat back to the vb6 apps?).

In essence, what we want if to compare the HASBYTE value saved in the MS SQL table against the resulting HASHBYTE value in the vb6 apps.  We think our process would be something like this with the code:

1. In the vb6 code ask the user for the password.
2. Convert that value to the HASHBYTE value. <-- (THIS IS WHERE WE WANT ASSISTANCE)
3. Read the SQL table and bring the HASHBYTE value already saved for comparison
4. Compare the users entry password's HASHBYTE value to what is saved in the SQL table.

Author Closing Comment

ID: 41881402
For some reason didn't quite read your entry.  We always re-read the entire question prior deleting one that there is no answer to.  Doing that we slowed down on your entry and modified some and it worked!  So pleasa excuse the delay and thanx!

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Modern/Metro styled message box and input box that directly can replace MsgBox() and InputBox()in Microsoft Access 2013 and later. Also included is a preconfigured error box to be used in error handling.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now