
ProTech-Online.com
Microsoft Visual Basic ASPX code example create user accounts behind code webpage.
Imports System.Data.SqlClient
Imports System.Security.Cryptography
Imports System.Web.Configuration
Partial Class admin_CreatingUserAccounts
Inherits System.Web.UI.Page
Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreateUserWizard1.CreatedUser
Dim RoleDropDown As DropDownList = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserRole"), DropDownList)
Dim cardnumber As TextBox = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("tbCreditCard"), TextBox)
Roles.AddUserToRole(CreateUserWizard1.UserName, RoleDropDown.Text)
If Not String.IsNullOrEmpty(cardnumber.Text) Then
Dim RSA As RSACryptoServiceProvider = New RSACryptoServiceProvider()
Dim publickey As String = RSA.ToXmlString(False)
Dim privatekey As String = RSA.ToXmlString(True)
Dim data As String = cardnumber.Text
Dim RSA2 As RSACryptoServiceProvider = New RSACryptoServiceProvider()
RSA2.FromXmlString(publickey)
Dim EncryptedByteData As Byte()
= RSA2.Encrypt(System.Text.Encoding.Unicode.GetBytes(data), False)
Dim EncryptedStrAsString As String = Convert.ToBase64String(EncryptedByteData)
Dim myConnection As SqlConnection = New SqlConnection(WebConfigurationManager.ConnectionStrings("TestConnectionString").ToString())
myConnection.Open()
Dim myCommand As SqlCommand = New SqlCommand("add_cards", myConnection)
myCommand.CommandType = System.Data.CommandType.StoredProcedure
myCommand.Parameters.AddWithValue("@userid",
CreateUserWizard1.UserName)
myCommand.Parameters.AddWithValue("@cardnumber", EncryptedStrAsString)
myCommand.Parameters.AddWithValue("@lastfour", cardnumber.Text.Substring(cardnumber.Text.Length - 4, 4))
myCommand.Parameters.AddWithValue("@privatekey", privatekey)
myCommand.Parameters.AddWithValue("@publickey", publickey)
myCommand.ExecuteNonQuery()
myConnection.Close()
End If
End Sub
End Class
Copyright © 2013 ProTechs-Online.com; All rights reserved.