Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 23rd, 2007, 02:24 PM
Authorized User
 
Join Date: Apr 2005
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Okay, I am lost on all the logic I see above so I am going to assume that you are working on a converter to convert your database passwords from plain text to SHA1. To do this, your way is going to have unpredictable results. You are missing your primary key so you can tell what record you are specifically editing and you aren't really looping through each password.

I can't write VB fluently, but I can understand it so I will just put in plain text what I think should happen.

First, do not reuse the connection, command or data adapter/reader for input and output into the database. Instead you will need a separate Connection, command and adapter or datasource for input and output.

First focus on the code that will cycle through your database and retrieve the password and whatever the primary key is. Get that part working first and output it to a textbox so you have a list showing the primary key column and the password. You will have to use a "While" loop with the datareader like gBianchi mentioned above because that reader keeps reading records each time the read method is called and returns true until there are no more record to return and then it returns false. Each call of the read method cycles to the next record found according to your query.

Once you are sure you have your data being retrieved, change the output lines you added to output your data to a textbox and change them to a method that will take the key and the password. You will create a new method that will access the database from a totally different connection, command and datawriter. This will just be used to update the record but you will add a "Where" clause to specify when the primary key equals the primary key you sent to the method. After you are done, make sure you close the writer.

What should happen is each password that is read with the primary key is passed to the update method. In there you will convert the password and then update the matching record. Since the whole thing is in a while loop, it will keep going until the datareader reads null. :)

A easier process, if the database is small, is just fill a data table with the same info and cycle through that and convert the password and then update with the newly updated datatable. :)

 
Old January 23rd, 2007, 02:31 PM
Friend of Wrox
 
Join Date: May 2005
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default

quick209 write the code this explanation is confusing!!!!

 
Old January 23rd, 2007, 02:51 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

the explanation from Quick209 (sorry don't see your name anywhere) is perfect...
why you want us to write your code?? I write a small portion of it before.. you can go further with that..
we can help you if you have a specific problem, but in this case your problem is all the code!

read carefully what Quick209 write, and go slow understanding what are you want to achieve and if you get stuck
in a certain part we can help you again...


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
================================================== =========
 
Old January 23rd, 2007, 04:54 PM
Friend of Wrox
 
Join Date: May 2005
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your help . this simple code worked:

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

        Dim strSQL3 As String

        cnn.Open()

        Dim cnn2 As New SqlClient.SqlConnection(strConnection)
        strSQL3 = "UPDATE members_bkp2 set [email protected] where [email protected]"
        Dim Cmd2 As New SqlCommand(strSQL3, cnn2)
        cnn2.Open()


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


            Cmd2 = New SqlCommand(strSQL3, cnn2)

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

            Cmd2.ExecuteNonQuery()



        End While


        dr.Close()

 
Old January 23rd, 2007, 04:58 PM
Friend of Wrox
 
Join Date: May 2005
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default

by the way Quick209 thanks for your full explanation

 
Old January 23rd, 2007, 07:01 PM
Authorized User
 
Join Date: Apr 2005
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry, at work posting during dime time between my projects. Just saw the posts after my post. No problem. Was going to build a code example but it would have been in C#. If you got it, that's cool. If not, I can post a small sample of how it would fit together. I want to say you probably can use one connection to do everything but have to test as I always use datasets whenever I am doing anything involving EU retrieval with updating. To play safe you can use totally separate sql classes to do the job since it is only you wanting to do a quick conversion so memory is not an issue.






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





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