. Password-Encrypted registration page in net

Source: Internet
Author: User
Tags md5 sha1
Encryption | The page provides an encryption function in the asp.net. The namespace System.Web.Security contains the class FormsAuthentication, which has a method hashpasswordforstoringinconfigfile. This method can turn user-supplied characters into garbled and then store them. Note that this method is not inherited.
The following code is the process of encrypting data and storing it in a database when you do a registration page
Imports System.Web.Security
Imports System.Data
namespaces required for Imports System.Data.SqlClient '////////

Private Sub button1_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Button1.Click
Dim Passformate as String
'///////////////encryptpassword Call function
Passformate = Encryptpassword (uid. Text, "MD5") '//////////or Encryptpassword (UID. Text, "SHA1")
' TextBox2.Text = Encryptpassword (uid. Text, "MD5")
' TextBox3.Text = Encryptpassword (uid. Text, "SHA1")
'///////////, let's test this out for ourselves.
' Textbox4.text = Formsauthentication.formscookiename
' Textbox5.text = Formsauthentication.formscookiepath
' Textbox6.text = Formsauthentication.getredirecturl (uid. Text, True)
' Formsauthentication.setauthcookie (UID. Text, True)

Dim SQL as String = "INSERT into pwd (UID,PWD) VALUES (@uid, @pwd)"
Dim Comm as SqlCommand = New SqlCommand (SQL, conn)
Conn. Open ()
Comm. Parameters.Add (New SqlParameter ("@uid", SqlDbType.Char, 16))
Comm. Parameters ("@uid"). Value = uid. Text
Comm. Parameters.Add (New SqlParameter ("@pwd", SqlDbType.Char, 16))
Comm. Parameters ("@pwd"). Value = Passformate
Comm. ExecuteNonQuery ()

End Sub

'////////////////defines cryptographic functions that can be invoked at any time.
Function Encryptpassword (ByVal password As String, ByVal passwordformate as String)
If passwordformate = "SHA1" Then
Encryptpassword = formsauthentication.hashpasswordforstoringinconfigfile (password, "SHA1")
ElseIf passwordformate = "MD5" Then
Encryptpassword = formsauthentication.hashpasswordforstoringinconfigfile (password, "MD5")
Else
Encryptpassword = ""
End If

End Function
As for the user verification is the same idea.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.