• Viernes 19 de Abril de 2024, 09:01

Autor Tema:  ENDURESER LA SEGURIDAD DE BD  (Leído 1680 veces)

kasq

  • Nuevo Miembro
  • *
  • Mensajes: 5
    • Ver Perfil
ENDURESER LA SEGURIDAD DE BD
« en: Martes 2 de Diciembre de 2008, 06:39 »
0
mi area de trabajo es:
Ms Visula Studio 2005 professional edition - .NET Framework 2.0.50727
REALIZE UNA CONEXION A UNA BASE DE DATOS EN ACCESS 2003 CON "Provider=Microsoft.Jet.OLEDB.4.0"
ComprUEBO EL usuario y clave usando La base de datos Y ME RESULTA PERFECTA.

QUISIERA ENDUREZER LA SEGURIDAD DE ACCESO A LA MISMA DESDE VS 2005 ENCRIPTANDO LA CONTRASEÑA DEL USUARIO CUANDO ESTE PASE POR LA FORMA DE LOGIN.

este es la adaptacion del codigo que he hecho asta el momento
Código: Text
  1. Imports System.Windows.Forms
  2. Imports System.Drawing
  3. Imports System.Data
  4. Imports System.Data.OleDb
  5. Public Class frmInicio
  6.     Private veces As Integer = 0
  7.     Private Const NumeroIntentos As Integer = 3
  8.     Private cadenaCnn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=transporte.mdb"
  9.  
  10.     Private Sub btnACEPTAR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnACEPTAR.Click
  11.         'If TxtClave.Text = "911" Then
  12.         If ComprobarUsuario(txtNICK.Text, txtCLAVE.Text) Then
  13.             'Dim claveSHA As String = Me.generarClaveSHA1(Me.TxtClave.Text)
  14.             'If ComprobarUsuario(Me.TxtUsuario.Text, claveSHA) Then
  15.             Me.DialogResult = Windows.Forms.DialogResult.OK
  16.             'Form1.Show()
  17.         Else
  18.             veces = veces + 1
  19.             If veces < NumeroIntentos Then
  20.                 Label3.Text = "Quedan " & (NumeroIntentos - veces) & " intentos"
  21.                 Exit Sub
  22.             End If
  23.             Me.DialogResult = Windows.Forms.DialogResult.No
  24.         End If
  25.         Hide()
  26.     End Sub
  27.  
  28.     Private Sub btnSALIR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSALIR.Click
  29.         Me.DialogResult = Windows.Forms.DialogResult.Cancel
  30.         Hide()
  31.     End Sub
  32.     Private Function ComprobarUsuario( _
  33.             ByVal IDUsuario As String, _
  34.             ByVal IDContraseña As String) As Boolean
  35.  
  36.         Dim cnn As OleDbConnection = Nothing
  37.         '
  38.         Try
  39.  
  40.             cnn = New OleDbConnection(cadenaCnn)
  41.             cnn.Open()
  42.  
  43.             Dim sel As New System.Text.StringBuilder
  44.  
  45.             sel.Append("SELECT COUNT (*) FROM Usuarios ")
  46.             sel.Append("WHERE IDUsuario = @IDUsuario AND IDContraseña = @IDContraseña")
  47.  
  48.             Dim cmd As New OleDbCommand(sel.ToString, cnn)
  49.  
  50.             cmd.Parameters.Add("@IDUsuario", OleDbType.VarChar, 50)
  51.             cmd.Parameters.Add("@IDContraseña", OleDbType.VarChar, 40)
  52.  
  53.             cmd.Parameters("@IDUsuario").Value = IDUsuario
  54.             cmd.Parameters("@IDContraseña").Value = IDContraseña
  55.  
  56.             Dim t As Integer = CInt(cmd.ExecuteScalar())
  57.  
  58.             cnn.Close()
  59.  
  60.             If t = 0 Then
  61.                 Return False
  62.             End If
  63.  
  64.         Catch ex As Exception
  65.             MessageBox.Show("ERROR al conectar a la base de datos: " & vbCrLf & _
  66.                         ex.Message, "Comprobar usuario", MessageBoxButtons.OK, _
  67.                         MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
  68.             Return False
  69.         Finally
  70.             If Not cnn Is Nothing Then
  71.                 cnn.Dispose()
  72.             End If
  73.         End Try
  74.  
  75.         Return True
  76.     End Function
  77. end class
  78.  

RadicalEd

  • Moderador
  • ******
  • Mensajes: 2430
  • Nacionalidad: co
    • Ver Perfil
Re: ENDURESER LA SEGURIDAD DE BD
« Respuesta #1 en: Miércoles 10 de Diciembre de 2008, 23:42 »
0
Utiliza la clase System.Security.Cryptography

Código: Visual Basic
  1. Imports Microsoft.VisualBasic
  2. Imports System.Security.Cryptography
  3. Imports System.IO
  4.  
  5. Public Class CommonFunctions2
  6.    Public Shared Function MD5Encrypt(ByVal str As String) As String
  7.  
  8.        'Imports System.Security.Cryptography
  9.  
  10.        Dim md5 As MD5CryptoServiceProvider
  11.        Dim bytValue() As Byte
  12.        Dim bytHash() As Byte
  13.        Dim strOutput As String
  14.        Dim i As Integer
  15.  
  16.        ' Create New Crypto Service Provider Object
  17.       md5 = New MD5CryptoServiceProvider
  18.  
  19.        ' Convert the original string to array of Bytes
  20.       bytValue = System.Text.Encoding.UTF8.GetBytes(str)
  21.  
  22.        ' Compute the Hash, returns an array of Bytes
  23.       bytHash = md5.ComputeHash(bytValue)
  24.        md5.Clear()
  25.  
  26.        For i = 0 To bytHash.Length - 1
  27.            'don't lose the leading 0
  28.           strOutput &= bytHash(i).ToString("x").PadLeft(2, "0")
  29.        Next
  30.  
  31.        MD5Encrypt = strOutput
  32.  
  33.    End Function
  34. End Class
  35.  
Extraida de techinterviews
El pasado son solo recuerdos, el futuro son solo sueños