Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...Help Needed in encrypting password in dnn 5.6.2Help Needed in encrypting password in dnn 5.6.2
Previous
 
Next
New Post
6/19/2011 10:04 AM
 
Hi,

I am facing a problem with encrypting password and creating password salt in dnn 5.6.2. I tried to create password salt and password using sha1 but when i try to login it is not validating the user with the encrypted password.

I want to know how DNN encrypts the password and creates the password salt in aspnetmembership table.

Any one please help me in encrypting the password and in creating the password salt. Please treat is as urgent.

Regards,
Sandeep 
 
New Post
6/19/2011 4:49 PM
 
DNN is built on the standard ASP .Net features. 

I believe all you need do is configure the membership provider.

Best wishes,
- Richard
Agile Development Consultant, Practitioner, and Trainer
www.dynamisys.co.uk
 
New Post
6/21/2011 1:33 AM
 
Hi,

Could you help me in configuring the membership provider. I am new to dotnetnuke
 
New Post
6/21/2011 5:32 AM
 
It's not dotnetnuke.  It's ASP .Net - http://lmgtfy.com/?q=SqlMembershipPro... 

Best wishes,
- Richard
Agile Development Consultant, Practitioner, and Trainer
www.dynamisys.co.uk
 
New Post
6/22/2011 12:51 AM
 
Hi 

I encrypted the password and updating the aspnet membership table but I cannot login with the changed password. Could anyone help to solve this problem

Here is my code 


Private Sub cmdLogin_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdLogin.Click


            If (UseCaptcha And ctlCaptcha.IsValid) OrElse (Not UseCaptcha) Then

                Dim loginStatus As UserLoginStatus = UserLoginStatus.LOGIN_FAILURE
                Dim objUser As UserInfo = UserController.ValidateUser(PortalId, txtUsername.Text, txtPassword.Text, "DNN", txtVerification.Text, PortalSettings.PortalName, IPAddress, loginStatus)
                Dim authenticated As Boolean = Null.NullBoolean
                Dim message As String = Null.NullString

'if login status failed then i am checking the user password with other db user password which is MD5
                If loginStatus = UserLoginStatus.LOGIN_FAILURE Then
                    Dim oUserInfo As New UserInfo()
                    Dim md5Hasher As New MD5CryptoServiceProvider()
                    Dim con As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("SiteSqlServer").ConnectionString)
                    con.Open()
                    Dim Password As String = txtPassword.Text
                    Dim hashedBytes As [Byte]()
                    Dim encoder As UTF7Encoding = New UTF7Encoding()
                    hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(Password))
                    Password = BitConverter.ToString(hashedBytes)
                    Password = Password.ToString.Replace("-", "").ToLower
                    Dim isMatch As Boolean = False
                    Dim cmdd As New SqlCommand(String.Format("select * from Users_Old where Username='{0}'", txtUsername.Text), con)
                    Dim dr As SqlDataReader = cmdd.ExecuteReader()
                    While dr.Read()
                        If dr("password").ToString = Password.ToString Then
                            isMatch = True
                        End If
                    End While
                    dr.Close()
                    con.Close()

'if the MD5 password matches then i am encrypting the password to SHA1

                    If isMatch Then
                        oUserInfo = DotNetNuke.Entities.Users.UserController.GetUserByName(PortalSettings.PortalId, txtUsername.Text)


                        Dim mempass As String = ComputeHash(txtPassword.Text, "SHA1", Nothing)
                        con.Open()
                        Dim str As String = "Update aspnet_Membership set Password= '" & mempass & "' where Email= '" & oUserInfo.Email & "'"
                        Dim cm As New SqlCommand(String.Format(str), con)
                        Dim res As Boolean = cm.ExecuteNonQuery()

If res Then
loginStatus = UserLoginStatus.LOGIN_SUCCESS
End If

                    End If


                End If




                If loginStatus = UserLoginStatus.LOGIN_USERNOTAPPROVED Then
                    'Check if its the first time logging in to a verified site
                    If PortalSettings.UserRegistration = PortalRegistrationType.VerifiedRegistration Then
                        If Not rowVerification1.Visible Then
                            'Display Verification Rows so User can enter verification code
                            rowVerification1.Visible = True
                            rowVerification2.Visible = True
                            message = "EnterCode"
                        Else
                            If txtVerification.Text <> "" Then
                                message = "InvalidCode"
                            Else
                                message = "EnterCode"
                            End If
                        End If
                    Else
                        message = "UserNotAuthorized"
                    End If
                Else
                    authenticated = (loginStatus <> UserLoginStatus.LOGIN_FAILURE)
                End If


                'Raise UserAuthenticated Event
                Dim eventArgs As UserAuthenticatedEventArgs = New UserAuthenticatedEventArgs(objUser, txtUsername.Text, loginStatus, "DNN")
                eventArgs.Authenticated = authenticated
                eventArgs.Message = message
                OnUserAuthenticated(eventArgs)


            End If


        End Sub


        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 Case 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 hashValue As String
            hashValue = Convert.ToBase64String(hashWithSaltBytes)


            ' Return the result.
            ComputeHash = hashValue
        End Function

regards,
Sandeep
 
Previous
 
Next
HomeHomeOur CommunityOur CommunityGeneral Discuss...General Discuss...Help Needed in encrypting password in dnn 5.6.2Help Needed in encrypting password in dnn 5.6.2


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out