Visual Basic.NET - Login form

 
Vista:

Login form

Publicado por Paul (7 intervenciones) el 12/12/2007 18:38:59
Hola Bueno antes de nada gracias a todos auqellos que se toman el tiempo de leer y de brindar ayuda.
Mi tea es el siguiente me gustaria hacer un formulario de logeo dnd los password esten ecrypatados y demas.Que tenga cierto gardo de seguridad.
Alguien tiene hecho alguno que pueda pasarme el codigo para yo modificarlo.La base de datos q uso es microsoft sql

saludos
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

RE:Login form

Publicado por P. J. (706 intervenciones) el 12/12/2007 20:56:49
AQUI TE DEJO LA CLASE QUE YO USO:

Imports System.Security.Cryptography
Imports System.Text
Imports System.IO

Public Class Seguridad

Private mbytKey(7) As Byte
Private mbytIV(7) As Byte

Private Function convierteLlave(ByVal strLlave As String) As Boolean
Try
Dim bp(strLlave.Length - 1) As Byte
Dim aEnc As ASCIIEncoding = New ASCIIEncoding()
aEnc.GetBytes(strLlave, 0, strLlave.Length, bp, 0)

Dim sha As SHA1CryptoServiceProvider = New SHA1CryptoServiceProvider()
Dim bpHash() As Byte = sha.ComputeHash(bp)

Dim i As Integer
For i = 0 To 7
mbytKey(i) = bpHash(i)
Next i
For i = 8 To 15
mbytIV(i - 8) = bpHash(i)
Next

Return True

Catch e As Exception
Return False
End Try
End Function

Public Function encriptaDato(ByVal strDato As String) As String
Dim strResultado As String

If strDato.Length > 92160 Then
strResultado = "Error. Data String too large. Keep within 90Kb."
Return strResultado
End If

If Not (convierteLlave("LLAVE")) Then
strResultado = "Error. Fail to generate key for encryption"
Return strResultado
End If

strDato = String.Format("{0,5:00000}" & strDato, strDato.Length)

Dim rbData(strDato.Length - 1) As Byte
Dim aEnc As New ASCIIEncoding()
aEnc.GetBytes(strDato, 0, strDato.Length, rbData, 0)

Dim descsp As DESCryptoServiceProvider = New DESCryptoServiceProvider()

Dim desEncrypt As ICryptoTransform = descsp.CreateEncryptor(mbytKey, mbytIV)

Dim mStream As New MemoryStream(rbData)
Dim cs As New CryptoStream(mStream, desEncrypt, CryptoStreamMode.Read)
Dim mOut As New MemoryStream()

Dim bytesRead As Integer
Dim output(1023) As Byte
Do
bytesRead = cs.Read(output, 0, 1024)
If Not (bytesRead = 0) Then
mOut.Write(output, 0, bytesRead)
End If
Loop While (bytesRead > 0)

If mOut.Length = 0 Then
strResultado = ""
Else
strResultado = Convert.ToBase64String(mOut.GetBuffer(), 0, CInt(mOut.Length))
End If
Return strResultado

End Function

Public Function desencriptaDato(ByVal strDato As String) As String

Dim strResultado As String

If Not (convierteLlave("LLAVE")) Then
strResultado = "Error. Fail to generate key for decryption"
Return strResultado
End If

Dim nReturn As Integer = 0
Dim descsp As New DESCryptoServiceProvider()
Dim desDecrypt As ICryptoTransform = descsp.CreateDecryptor(mbytKey, mbytIV)

Dim mOut As New MemoryStream()
Dim cs As New CryptoStream(mOut, desDecrypt, CryptoStreamMode.Write)

Dim bPlain(strDato.Length - 1) As Byte
Try
bPlain = Convert.FromBase64CharArray(strDato.ToCharArray(), 0, strDato.Length)
Catch e As Exception
strResultado = "Error. Input Data is not base64 encoded."
Return strResultado
End Try

Dim lRead As Long = 0
Dim lReadNow As Long = 0
Dim lTotal As Long = strDato.Length

Try
Do While (lTotal >= lRead)
cs.Write(bPlain, 0, bPlain.Length)
lReadNow = CLng(((bPlain.Length / descsp.BlockSize) * descsp.BlockSize))
lRead = lReadNow + lRead
Loop

Dim aEnc As New ASCIIEncoding()
strResultado = aEnc.GetString(mOut.GetBuffer(), 0, CInt(mOut.Length))

Dim strLen As String = strResultado.Substring(0, 5)
Dim nLen As Integer = CInt(strLen)
strResultado = strResultado.Substring(5, nLen)
nReturn = CInt(mOut.Length)

Return strResultado

Catch e As Exception
strResultado = "Error. Decryption Failed. Possibly due to incorrect Key or corrupted data"
End Try
Return strResultado
End Function

End Class


PARA USARLO:
Instancias la clase, y llamas a ecripta o desencripta DATO y le pasas el valor
Estas funciones te retornan el valor encriptado y viceversa.

Espero te sea de utilidad.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Login form

Publicado por Paul (7 intervenciones) el 12/12/2007 21:15:30
Hola P. J. quimera muchas gracas por rsponder. Entiendo que tu clase sirve para encripar y viceversa, pero no tenes alguna aplicacion echar osea un formularioa algo ya desarrolaldo dnd hagas la conexion, validacion y encryptacion echo para pasarme y yo simplemente cambiar las varaibles ?? Me gustaria tener algo asi por el echo de entender toda una aplicacuion y no una parte del codigo ademas tb me ayiudaria para ver otra forma de desarrollo.
saludos y nuevamente garcias
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

RE:Login form

Publicado por P. J. (706 intervenciones) el 12/12/2007 23:00:11
Uhmm...

Ando de buen humor hoy. XD, aqui te dejo un login bastante sencillo:

Imports System.Data.SqlClient

Public Class Login

Dim oConexion As SqlConnection
Dim oAdaptador As SqlDataAdapter
Dim dt As New DataTable
Dim oSeguridad As New Seguridad

Private Sub btnIngresar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIngresar.Click
Dim strSQL As String = "SELECT * FROM TB_USUARIO WHERE NOMBRE_USU='" & Me.txtUsuario.Text & _
"' AND PASSWD_USU='" & oSeguridad.encriptaDato(Me.txtPasswd.Text) & "'"
oConexion = New SqlConnection("SERVER=(LOCAL); DATABASE=PRUEBA; UID=SA; PASSWORD=SA")
oAdaptador = New SqlDataAdapter(strSQL, oConexion)
oAdaptador.Fill(dt)
If dt.Rows.Count > 0 Then
MsgBox("Bienvenido...")
Else
MsgBox("Acceso Denegado")
End If
End Sub
End Class

Previo a esto en tu BD deben de estar encriptadas las claves, entonces en tu MANT. USUARIO al guardar el campo clave alli encriptas.

Salu2.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Login form

Publicado por isidro (1 intervención) el 23/06/2008 04:43:57
En el eveto click de boton coloca este codigo

If Me.UsernameTextBox.Text = "isidro" And Me.PasswordTextBox.Text = "pass" Then
MsgBox("Correcto!")
'Add code here that will run if logon successful
Else
MsgBox("Incorrecto username o password")
'Add Code here that will run if logon unsuccessful

End If
Me.Close()
End Sub
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar