Free Download:
|
| |
| vetter1 | Asp.Net User |
| Re: Using Password and Salt with SHA1 | 2/8/2004 5:13:33 PM |
0/0 | |
|
I've redone this using the following in the security.vb file
'http://www.obviex.com/samples/hash.aspx
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' SAMPLE: Hashing data with salt using MD5 and several SHA algorithms.
'
' To run this sample, create a new Visual Basic.NET project using the Console
' Application template and replace the contents of the Module1.vb file with
' the code below.
'
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
' WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
'
' Copyright (C) 2003. Obviex(TM). All rights reserved.
'
'Imports System
'Imports System.Text
'Imports System.Security.Cryptography
' <SUMMARY>
' This class generates and compares hashes using MD5, SHA1, SHA256, SHA384,
' and SHA512 hashing algorithms. Before computing a hash, it appends a
' randomly generated salt to the plain text, and stores this salt appended
' to the result. To verify another plain text value against the given hash,
' this class will retrieve the salt value from the hash string and use it
' when computing a new hash of the plain text. Appending a salt value to
' the hash may not be the most efficient approach, so when using hashes in
' a real-life application, you may choose to store them separately. You may
' also opt to keep results as byte arrays instead of converting them into
' base64-encoded strings.
' </SUMMARY>
'Public Class SimpleHash
' <SUMMARY>
' Generates a hash for the given plain text value and returns a
' base64-encoded result. Before the hash is computed, a random salt
' is generated and appended to the plain text. This salt is stored at
' the end of the hash value, so it can be used later for hash
' verification.
' </SUMMARY>
' <PARAM name="plainText">
' Plaintext value to be hashed. The function does not check whether
' this parameter is null.
' </PARAM>
' < name="hashAlgorithm">
' Name of the hash algorithm. Allowed values are: "MD5", "SHA1",
' "SHA256", "SHA384", and "SHA512" (if any other value is specified
' MD5 hashing algorithm will be used). This value is case-insensitive.
' </PARAM>
' < name="saltBytes">
' Salt bytes. This parameter can be null, in which case a random salt
' value will be generated.
' </PARAM>
' <RETURNS>
' Hash value formatted as a base64-encoded string.
' </RETURNS>
Public Shared Function ComputeHash(ByVal plainText As String, ByVal hashAlgorithm As String, ByVal saltBytes() As Byte) As String
' If salt is not specified, generate it on the fly.
If (saltBytes Is Nothing) Then
' Define min and max salt sizes.
Dim minSaltSize As Integer
Dim maxSaltSize As Integer
minSaltSize = 4
maxSaltSize = 8
' Generate a random number for the size of the salt.
Dim random As Random
random = New Random()
Dim saltSize As Integer
saltSize = random.Next(minSaltSize, maxSaltSize)
' Allocate a byte array, which will hold the salt.
saltBytes = New Byte(saltSize - 1){}
' Initialize a random number generator.
Dim rng As RNGCryptoServiceProvider
rng = New RNGCryptoServiceProvider()
' Fill the salt with cryptographically strong byte values.
rng.GetNonZeroBytes(saltBytes)
End If
' Convert plain text into a byte array.
Dim plainTextBytes As Byte()
plainTextBytes = Encoding.UTF8.GetBytes(plainText)
' Allocate array, which will hold plain text and salt.
Dim plainTextWithSaltBytes() As Byte = New Byte(plainTextBytes.Length + saltBytes.Length - 1){}
' Copy plain text bytes into resulting array.
Dim I As Integer
For I = 0 To plainTextBytes.Length - 1
plainTextWithSaltBytes(I) = plainTextBytes(I)
Next I
' Append salt bytes to the resulting array.
For I = 0 To saltBytes.Length - 1
plainTextWithSaltBytes(plainTextBytes.Length + I) = saltBytes(I)
Next I
' Because we support multiple hashing algorithms, we must define
' hash object as a common (abstract) base class. We will specify the
' actual hashing algorithm class later during object creation.
Dim hash As HashAlgorithm
' Make sure hashing algorithm name is specified.
If (hashAlgorithm Is Nothing) Then
hashAlgorithm = ""
End If
' Initialize appropriate hashing algorithm class.
Select hashAlgorithm.ToUpper()
Case "SHA1"
hash = New SHA1Managed()
Case "SHA256"
hash = New SHA256Managed()
Case "SHA384"
hash = New SHA384Managed()
Case "SHA512"
hash = New SHA512Managed()
Case Else
hash = New MD5CryptoServiceProvider()
End Select
' Compute hash value of our plain text with appended salt.
Dim hashBytes As Byte()
hashBytes = hash.ComputeHash(plainTextWithSaltBytes)
' Create array which will hold hash and original salt bytes.
Dim hashWithSaltBytes() As Byte = New Byte(hashBytes.Length + saltBytes.Length - 1) {}
' Copy hash bytes into resulting array.
For I = 0 To hashBytes.Length - 1
hashWithSaltBytes(I) = hashBytes(I)
Next I
' Append salt bytes to the result.
For I = 0 To saltBytes.Length - 1
hashWithSaltBytes(hashBytes.Length + I) = saltBytes(I)
Next I
' Convert result into a base64-encoded string.
Dim hashString As String
hashString = Convert.ToBase64String(hashWithSaltBytes)
' Return the result.
Return hashString
End Function
'************************************************
And I'm referrencing it in the register module as
UserId = objUser.AddUser(PortalId, txtFirstName.Text, txtLastName.Text, Address1.Unit, Address1.Street, Address1.City, Address1.Region, Address1.Postal, Address1.Country, Address1.Telephone, txtEmail.Text, txtUsername.Text, objSecurity.ComputeHash(txtPassword.Text, "SHA512", Nothing), IIf(_portalSettings.UserRegistration = 1, CStr(False), CStr(True)), UserId)
However, whenever I look at the passwords they are only 12 characters in length which is incorrect. What am I doing wrong?
vetter1 |
|
| |
Free Download:
|
Books: Information Security Management Handbook Authors: Harold F. Tipton, Micki Krause, Pages: 578, Published: 2005 Oracle Database 11g: New Features for DBAs and Developers Authors: Sam R. Alapati, Charles Kim, Pages: 602, Published: 2007 Handbook of Information Security: Threats, Vulnerabilities, Prevention, Detection, and Management Authors: Hossein Bidgoli, Pages: 3366, Published: 2006 The Hacker's Handbook: The Strategy Behind Breaking Into and Defending Networks Authors: J. Burke Hansen, Susan Elizabeth Young, Susan Young, Dave Aitel, Pages: 860, Published: 2003 PHP Solutions, Dynamic Web Design Made Easy: Dynamic Web Design Made Easy Authors: David Powers, SpringerLink (Online service, Pages: 0, Published: 2006 Pro PHP Security Authors: Chris Snyder, Michael Southwell, Pages: 500, Published: 2005 The Internet Encyclopedia: P - Z Authors: Hossein Bidgoli, Pages: 976, Published: 2004 Hardening Network Security: Network Security Authors: John Mallery, Jason Zann, Patrick Kelly, Wesley Noonan, Paul Love, Eric S. Seagren, Rob Kraft, Mark O'Neill, Pages: 608, Published: 2005 Advanced Rails Authors: Brad Ediger, Pages: 357, Published: 2007 Web:secure hashes in PHP using salt « Patrick’s development blog Feb 12, 2008 ... if (stored_password == sha1($salt.$password)) { print “You are logged in!”; }. I can write a more practical example of using salts someday. ... PHP MD5 + Salt + sha1 + base64_encde Encryption tutorial tips ... PHP MD5 + Salt + sha1 + base64_encde Encryption tutorial tips tricks and demos. ... $salt_pass = md5($password.$salt); ?> If you don't like the salt + MD5 ... PHP Security Consortium: Password Hashing Note: Using MySQL's password() function in your own applications isn't recommended ... The resulting string consists of the salt followed by the SHA-1 hash ... How To: Hash Data with Salt (C#/VB.NET) NET using MD5, SHA1, SHA256, SHA384, and SHA512 algoritnms. ... COMPARING PASSWORD HASHES MD5 (good): True MD5 (bad) : False SHA1 (good): True SHA1 (bad) ... Re: Change Auth component will solve hash without salt? When checking password, Auth always hashing using sha1 combine with >> > > security.salt. >> > > It's makes different value compare with my password in ... Salt your passwords | Tim Jansson password_hash = Digest::SHA1.hexdigest(”–#{salt}–#{password}–”) ... Instead of using the user’s “signup_date”, I used the “password_lastupdated” field in my ... Change Auth component will solve hash without salt? - CakePHP ... password in your DB "pure" SHA1? > If you're using the Auth component all the way, it will hash the > password including Salt when the user registers, ... Coverage Data #if NET_2_0 public PasswordDeriveBytes (byte[] password, byte[] salt) { Prepare (password, salt, "SHA1", 100); } public PasswordDeriveBytes (byte[] password ... Using SHA1 to hash passwords in 1.1 not playing nice in 2.0 - ASP ... using System.Security.Cryptography; using System.Text; public static string HashPassword(Guid salt, string password) { SHA1 hash = SHA1. ... PHP: sha1 - Manual If your still using sha1, here is a function that will hopefully help a little. .... You are much much better off adding a variable salt to passwords before ... |
|
Search This Site:
|
|