Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 23rd, 2007, 03:25 AM
Friend of Wrox
 
Join Date: May 2005
Location: , , .
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default password encode sha1 all records

hello,
i have a table with 200 records which has a password field
the passwords are not encoded
i need a page with a button when i click the button then
it goes and updates all the password fields to sha1 encoded
i have written some codes but it does not work
please write me the code

  Dim strPW As String = ""
        Dim dr As SqlDataReader



        Dim sql As String = "Select password from members_bkp"

        Dim cnn As New SqlClient.SqlConnection(strConnection)
        cnn.Open()

        Dim Cmd As New SqlCommand(Sql, cnn)

        dr = Cmd.ExecuteReader()
        dr.Read()
        Dim strPWEncoded As String = FormsAuthentication.HashPasswordForStoringInConfig File(dr("password"), "SHA1")
        dr.Close()
        Dim strSQL3 As String


        strSQL3 = "UPDATE members_bkp set password=@pwd"
        Cmd = New SqlCommand(strSQL3, cnn)
        Cmd.Parameters.Add(New SqlParameter("@pwd", strPWEncoded))
        Cmd.ExecuteNonQuery()


Reply With Quote
  #2 (permalink)  
Old January 23rd, 2007, 08:51 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there...

which part is not working??
if you want to updates all the fields to the same word why open a datareader before??
just the las part is ok...
Code:
    strSQL3 = "UPDATE members_bkp set password=@pwd"
    Cmd = New SqlCommand(strSQL3, cnn)
    Cmd.Parameters.Add(New SqlParameter("@pwd", strPWEncoded))
    Cmd.ExecuteNonQuery()
also you say is not working... it's throw an error or is just not doing what is expected???

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
Reply With Quote
  #3 (permalink)  
Old January 23rd, 2007, 10:13 AM
Friend of Wrox
 
Join Date: May 2005
Location: , , .
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default

no it updates all the passwords to 1 sha1 string
i want each password field to be converted to its own sha1

Reply With Quote
  #4 (permalink)  
Old January 23rd, 2007, 11:33 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

ok... and what part is not working?? because the logic of that function is no good...

you have to loop around all the records and update one at a time...

you still didn't tell us which part is no working...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
Reply With Quote
  #5 (permalink)  
Old January 23rd, 2007, 11:50 AM
Friend of Wrox
 
Join Date: May 2005
Location: , , .
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok i really do not know
i tell you it works but all of the record get updated with one password
can you write the code so it loops and updates each record!!

Reply With Quote
  #6 (permalink)  
Old January 23rd, 2007, 12:02 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

you need to read the password for each record..

doing this
Code:
    dr.Read()
    Dim strPWEncoded As String = FormsAuthentication.HashPasswordForStoringInConfigFile(dr("password"), "SHA1")
    dr.Close()
will only read the password for the first record

you have to change your logic to something like this:

Code:
    Dim strPW As String = ""
    Dim dr As SqlDataReader
    Dim strSQL3 As String
    Dim sql As String = "Select password from members_bkp"
    Dim cnn As New SqlClient.SqlConnection(strConnection)
    cnn.Open()
    strSQL3 = "UPDATE members_bkp set password=@pwd"
    Cmd = New SqlCommand(strSQL3, cnn)
    Dim Cmd As New SqlCommand(Sql, cnn)
    dr = Cmd.ExecuteReader()
    do while dr.Read()
        Dim strPWEncoded As String = FormsAuthentication.HashPasswordForStoringInConfigFile(dr("password"), "SHA1")
        Cmd.Parameters.Add(New SqlParameter("@pwd", strPWEncoded))
        Cmd.ExecuteNonQuery()
    end while
    dr.Close()
NOTE: the above will not work ok because the update command needs a where clause to tell it which record to update.. you will have to add it to the update command because I don't know your tables...






HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
Reply With Quote
  #7 (permalink)  
Old January 23rd, 2007, 12:30 PM
Friend of Wrox
 
Join Date: May 2005
Location: , , .
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i am really confused
what should i write in the parameters collection
i have this code

Dim strSQL3 As String
        Dim sql As String = "Select password from members_bkp"
        Dim cnn As New SqlClient.SqlConnection(strConnection)
        cnn.Open()
        Dim Cmd As New SqlCommand(sql, cnn)


        strSQL3 = "UPDATE members_bkp set password=@pwd"
        Cmd = New SqlCommand(strSQL3, cnn)


        Cmd.Parameters.Add(New SqlParameter("@pwd", dr("password")))
        dr = Cmd.ExecuteReader()
        While dr.Read()
            Dim strPWEncoded As String = FormsAuthentication.HashPasswordForStoringInConfig File(dr("password"), "SHA1")
            Cmd.Parameters.Add(New SqlParameter("@pwd", strPWEncoded))
            Cmd.ExecuteNonQuery()
        End While
        dr.Close()



Reply With Quote
  #8 (permalink)  
Old January 23rd, 2007, 12:44 PM
Friend of Wrox
 
Join Date: May 2005
Location: , , .
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I get error "there is already an open datareader"
on line :Cmd.ExecuteNonQuery()


 Dim strPW As String = ""
        Dim dr As SqlDataReader

        Dim cnn As New SqlClient.SqlConnection(strConnection)
        Dim sql As String = "Select password from members_bkp"
        Dim Cmd As New SqlCommand(Sql, cnn)




        cnn.Open()

        dr = Cmd.ExecuteReader()
        While dr.Read()
            Dim strPWEncoded As String = FormsAuthentication.HashPasswordForStoringInConfig File(dr("password"), "SHA1")

            Dim strSQL3 As String
            strSQL3 = "UPDATE members_bkp set password=@pwd"
            Cmd = New SqlCommand(strSQL3, cnn)
            Cmd.Parameters.Add(New SqlParameter("@pwd", strPWEncoded))
            Cmd.ExecuteNonQuery()
        End While



Reply With Quote
  #9 (permalink)  
Old January 23rd, 2007, 01:09 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

well.. you cannot use a command for a reader and at the same time for a command...

you will need another command...


HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
Reply With Quote
  #10 (permalink)  
Old January 23rd, 2007, 01:18 PM
Friend of Wrox
 
Join Date: May 2005
Location: , , .
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I use the following code with a new command but i get this error:
There is already an open DataReader associated with this Command which must be closed first.

Dim cnn As New SqlClient.SqlConnection(strConnection)
        Dim sql As String = "Select password from members_bkp"
        Dim Cmd As New SqlCommand(sql, cnn)

        Dim strSQL3 As String

        cnn.Open()

        strSQL3 = "UPDATE members_bkp set password=@pwd"
        Dim Cmd2 As New SqlCommand(strSQL3, cnn)
        dr = Cmd.ExecuteReader()
        While dr.Read()
            Dim strPWEncoded As String = FormsAuthentication.HashPasswordForStoringInConfig File(dr("password"), "SHA1")

            Cmd2 = New SqlCommand(strSQL3, cnn)

            Cmd2.Parameters.Add(New SqlParameter("@pwd", strPWEncoded))

            Cmd2.ExecuteNonQuery()
        End While

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[HOW TO] Decode / Decrypt Sha1 ??? oscarestany PHP How-To 1 August 6th, 2007 05:49 PM
SHA1 Encryption/Decryption help kakko72 VS.NET 2002/2003 7 November 15th, 2004 07:20 PM
SHA1 Encryption/Decryption help kakko72 General .NET 2 April 16th, 2004 03:12 PM
need help on auto encode rachelwong ASP.NET 1.0 and 1.1 Basics 1 December 11th, 2003 12:37 AM
encode alihussein3 Javascript 1 October 28th, 2003 05:21 AM



All times are GMT -4. The time now is 04:32 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.