Saturday, March 24, 2012

MD5 and MS Access

I want to use the Security.Cryptography class to create an MD5 encrypted
password, as detailed here..
http://aspnet.4guysfromrolla.com/articles/112002-1.aspx
However, I'm using an MS Access database. Does Access have a Binary field
(cant find it!)? The only thing I can find is the OLE data type - would that
work for storing MD5'd passwords?
Or, do I need to migrate to SQL server?
Cheers
Danmusosdev wrote:
> I want to use the Security.Cryptography class to create an MD5 encrypted
> password, as detailed here..
> http://aspnet.4guysfromrolla.com/articles/112002-1.aspx
> However, I'm using an MS Access database. Does Access have a Binary field
> (cant find it!)? The only thing I can find is the OLE data type - would th
at
> work for storing MD5'd passwords?
> Or, do I need to migrate to SQL server?
> Cheers
>
> Dan
Why not use a string field? MD5 isn't binary its plaintext.

"Ray Booysen" wrote:

> musosdev wrote:
> Why not use a string field? MD5 isn't binary its plaintext.
>
ok, now I'm *really* !
The code fro, the 4guys page generates a hash into a Byte array !? How do I
use the MD5 cryptography routines to generate a hash and store it in a strin
g
field?!
You should be able to do this
DbField = array1.toString
"musosdev" <musoswire@.community.nospam> wrote in message
news:558657D7-6570-4A8D-BC3D-8DF862ACD4EB@.microsoft.com...
>
> "Ray Booysen" wrote:
>
> ok, now I'm *really* !
> The code fro, the 4guys page generates a hash into a Byte array !? How do
> I
> use the MD5 cryptography routines to generate a hash and store it in a
> string
> field?!
Hi,
Thank you for your post.
The 128-bit (16-byte) MD5 hashes (also termed message digests) are
typically represented as a sequence of 32 hexadecimal digits. You can use
following code to convert the byte array to a hex string:
Dim i As Integer = 0, md5 As String = String.Empty
For i = 0 To hashedBytes.Length - 1
md5 += hashedBytes(i).ToString("x")
Next
Hope this helps. Please feel free to post here if anything is unclear.
Regards,
Walter Wang (wawang@.online.microsoft.com, remove 'online.')
Microsoft Online Community Support
========================================
==========
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
========================================
==========
This posting is provided "AS IS" with no warranties, and confers no rights.
Sorry, I've made a typo in my last post about the code. Should be "x2"
instead of "x":
Dim i As Integer = 0, md5 As String = String.Empty
For i = 0 To hashedBytes.Length - 1
md5 += hashedBytes(i).ToString("x2")
Next
You can find more information here:
#MD5 Class
http://msdn2.microsoft.com/en-us/li...tography.md5.as
px
Regards,
Walter Wang (wawang@.online.microsoft.com, remove 'online.')
Microsoft Online Community Support
========================================
==========
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
========================================
==========
This posting is provided "AS IS" with no warranties, and confers no rights.
Hi Walter
That works cheers (well, it's gone into the database anyway!).
Just one thing that's confusing me. You said..

> The 128-bit (16-byte) MD5 hashes (also termed message digests) are
> typically represented as a sequence of 32 hexadecimal digits
However, when I look at the database there are only 30 characters being put
into the Password field.
Is that right or is my code screwing something up somewhere?
Cheers
Dan
"Walter Wang [MSFT]" wrote:

> Sorry, I've made a typo in my last post about the code. Should be "x2"
> instead of "x":
> Dim i As Integer = 0, md5 As String = String.Empty
> For i = 0 To hashedBytes.Length - 1
> md5 += hashedBytes(i).ToString("x2")
> Next
>
> You can find more information here:
> #MD5 Class
> [url]http://msdn2.microsoft.com/en-us/library/system.security.cryptography.md5.as[/ur
l]
> px
> Regards,
> Walter Wang (wawang@.online.microsoft.com, remove 'online.')
> Microsoft Online Community Support
> ========================================
==========
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ========================================
==========
> This posting is provided "AS IS" with no warranties, and confers no rights
.
>
Hi Dan,
Thank you for your update.
I hope you're not using my incorrect function in my first post (which is
corrected in my second post).
You can also verify the output of the empty string's hash value, which
should be "d41d8cd98f00b204e9800998ecf8427e".
Please feel free to post here if anything is unclear.
Regards,
Walter Wang (wawang@.online.microsoft.com, remove 'online.')
Microsoft Online Community Support
========================================
==========
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
========================================
==========
This posting is provided "AS IS" with no warranties, and confers no rights.
Hi Walter,
Thanks for the blank hash - that sorted it for me. Perfect.. but missing the
7e off the end...
Anyway, went through the code, and I'd done
i=0; i<hash.Length-1
which of course will lose me one character!
Sorted now, and all passwords are salted and hashing at 32 chars. Perfect!
Thanks for your help!
"Walter Wang [MSFT]" wrote:

> Hi Dan,
> Thank you for your update.
> I hope you're not using my incorrect function in my first post (which is
> corrected in my second post).
> You can also verify the output of the empty string's hash value, which
> should be "d41d8cd98f00b204e9800998ecf8427e".
> Please feel free to post here if anything is unclear.
> Regards,
> Walter Wang (wawang@.online.microsoft.com, remove 'online.')
> Microsoft Online Community Support
> ========================================
==========
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ========================================
==========
> This posting is provided "AS IS" with no warranties, and confers no rights
.
>
Hi Dan,
Thank you for your update.
I'm sorry I should have made myself clear that my sample code is written in
VB.NET. Apparently you're using C#.
That's the difference between VB.NET and C#, VB.NET "to" means "<=", so we
have to use "to hash.Length - 1" in VB.NET and "< hash.Length" in C#.
Anyway, I am glad to hear that the problem has been fixed. If you have any
other questions or concerns, please do not hesitate to contact us. It is
always our pleasure to be of assistance.
Have a nice day!
Regards,
Walter Wang (wawang@.online.microsoft.com, remove 'online.')
Microsoft Online Community Support
========================================
==========
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
========================================
==========
This posting is provided "AS IS" with no warranties, and confers no rights.

No comments:

Post a Comment