Results 1 to 10 of 10

Thread: [2005] Encrypt and Decrypt login

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    258

    [2005] Encrypt and Decrypt login

    Hi this is where i declare my encryption and decryption in my login form..

    Code:
      Dim strSQL As String = "SELECT * FROM UserLoginProfile WHERE [Username] = '" & txtUserName.Text & "' AND [Password] = '" & EncDec(txtPassword.Text) & "'"
    now this is my public function for the EncDec

    Code:
    Public Function EncDec(ByVal strPassword As String) As String
            Dim Counter As Integer
    
            EncDec = ""
    
            For Counter = 1 To strPassword.Length
                EncDec = EncDec & Chr(Asc(Mid(strPassword, Counter, 1)) + 70)
            Next
    
            Return EncDec
    
        End Function
    it used to work on our VB.Net 03 program so i used in in our other project using VB 05 language.. any help converting / fixing? thanks
    Last edited by aerialz666; Jul 20th, 2007 at 11:37 AM.

  2. #2
    New Member
    Join Date
    Jul 2007
    Location
    Hanoi.VietNam
    Posts
    12

    Re: [2005] Encrypt and Decrypt login

    i think this block of statements can be used in vb.net 2005 very original.
    but why have you choose 70 ?
    Last edited by gago; Jul 20th, 2007 at 12:27 PM.

  3. #3
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: [2005] Encrypt and Decrypt login

    Works fine as is for me.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  4. #4
    Addicted Member
    Join Date
    Mar 2006
    Posts
    235

    Re: [2005] Encrypt and Decrypt login

    FYI. SQL Server 2005 now has built in encryption. There is a good example in using it at http://blogs.msdn.com/lcris/archive/...09/427523.aspx

  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] Encrypt and Decrypt login

    The .NET framework in general has built in encryption of several types. I would recommend using either that or possibly encryption right on the server as Ken B mentions.

    Your method is not very secure, as it could be easily cracked if needed.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    258

    Re: [2005] Encrypt and Decrypt login

    hi thanks for the replies, but this is the only encryption i know and it aint working, what happens is that whene i add the encyption, it says that the pw i entered is invalid when in fact it is correct, can anyone help me fix it? or teach me the SQL built in encryption.. (im not really good) thanks

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    258

    Re: [2005] Encrypt and Decrypt login

    this is my button click for my login..

    Code:
     Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
            Dim cmd As SqlCommand
            Dim Reader As SqlDataReader
            Dim strSQL As String = "SELECT * FROM UserLoginProfile WHERE [Username] = '" & txtUserName.Text & "' AND [Password] = '" & EncDec(txtPassword.Text) & "'"
            Dim conn As New SqlConnection("Data Source=stephen\prac2server;Initial Catalog=FinalDB;Integrated Security=SSPI")
            Dim password As String = ""
            Dim username As String = ""
    
            If String.IsNullOrEmpty(txtUserName.Text) Then
                MessageBox.Show("Please type your username.")
                txtUserName.Focus()
            ElseIf String.IsNullOrEmpty(txtPassword.Text) Then
                MessageBox.Show("Please type your password.")
                txtPassword.Focus()
            Else
                cmd = New SqlCommand(strSQL, conn)
                Try
                    conn.Open()
                Catch ex As Exception
                    MsgBox("Error connecting to database.  This could mean a deleted or moved database file.  Suggestion: Reinstallation.", MsgBoxStyle.Critical, "Missing Critical File")
                    Application.Exit()
                End Try
    
                Reader = cmd.ExecuteReader()
                If Reader.Read Then
                    username = Reader.GetValue(0)
                Else
                    MessageBox.Show("Use a valid username and correct password.")
                End If
    
                Reader.Close()
                conn.Close()
    
                If Not String.IsNullOrEmpty(username) Then
                    MessageBox.Show("Welcome " & username)
                    Me.Hide()
                    Home.Show()
                    Home.Focus()
                    Home.Refresh()
                End If
            End If
    
        End Sub

  8. #8
    Addicted Member
    Join Date
    Mar 2006
    Posts
    235

    Re: [2005] Encrypt and Decrypt login

    What database are you using?

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    258

    Re: [2005] Encrypt and Decrypt login

    i am using MS SQL server 2005 express

  10. #10
    Addicted Member
    Join Date
    Mar 2006
    Posts
    235

    Re: [2005] Encrypt and Decrypt login

    The attached project should explain the process.

    I wrote it when I was learning how to use symmetric keys, so it should help you.

    Click on the Create Database button to create a database with a user table containing a password field. If you get an error when you click on the code, reclick it and it should work the second time.

    There are two buttons to populate the table, one via sql and the other using a stored procedure.

    There is also two buttons to display the user information. One using the SYMMETRIC KEY, the other not.

    Look at the blog link I sent you above for more information on using keys.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width