Solved

How to compare ms sql hashbytes results within vb6

Posted on 2016-11-06
5
36 Views
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?
0
Comment
Question by:rayluvs
  • 3
5 Comments
 

Author Comment

by:rayluvs
Comment Utility
Hi,

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)

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

Sql:
SELECT HASHBYTES('SHA1', 'ExpertExchange')

Results:
0x8E054939FFEE22BFC46C7A381543148713EC3EFC


(see code attached)
SHA1-Hash.zip
0
 
LVL 32

Expert Comment

by:Stefan Hoffmann
Comment Utility
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.
0
 
LVL 17

Accepted Solution

by:
Pawan Kumar Khowal earned 500 total points
Comment Utility
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)
)
AS
BEGIN

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

--

Open in new window


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

Hope it helps !
0
 

Author Comment

by:rayluvs
Comment Utility
ste5an,

"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.
0
 

Author Closing Comment

by:rayluvs
Comment Utility
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!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 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

12 Experts available now in Live!

Get 1:1 Help Now