techpreparation-homepage

Home  Interview Questions  Aptitude Questions  Tutorials  Placement Papers  Search  Resume Guide  Soft Skills  Video  Forum  Blog


Technical Interview Questions

Visual Basic Interview Question
.NET Web Interview Questions
.NET Interview Questions
C# Interview Questions
                              .........More

Source Codes
Asp .NET Source Codes
Asp VB Script Source Codes
                              .........More

Soft Skills
Communication Skills
Leadership Skills
                              .........More

Subscribe to our Newsletters
Name:
Email:

 

 

  

Asp.Net Source Codes

Create new password digests in the WEB.CONFIG file dynamically at runtime

Imports System.Text
Imports System.Web.Security
Imports System.Xml

Public Class AddUsers
Inherits System.Web.UI.Page

Protected WithEvents btnCreate As System.Web.UI.WebControls.Button
Protected WithEvents txtPassword As System.Web.UI.HtmlControls.HtmlInputText
Protected WithEvents txtUsername As System.Web.UI.WebControls.TextBox

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
_
Private Sub InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub btnCreate_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles btnCreate.Click

Dim strPlainText As String = txtPassword.Value
Dim strUsername As String = txtUsername.Text

If strPlainText <> "" And strUsername <> "" Then
Dim strHash As String = _
FormsAuthentication.HashPasswordForStoringInConfigFile( _
strPlainText, _
"sha1")

strPlainText = ""

'**********************************************
'Open config file and build new password digest
'**********************************************
Dim doc As New XmlDocument()

doc.Load(Server.MapPath("..\Web.config"))

Dim newElement As XmlElement = doc.CreateElement("user")

Dim attribName As XmlAttribute = doc.CreateAttribute("name")
attribName.Value = strUsername

Dim attribPassword As XmlAttribute = doc.CreateAttribute("password")
attribPassword.Value = strHash

newElement.Attributes.Append(attribName)
newElement.Attributes.Append(attribPassword)

Dim credentials As XmlElement = doc.GetElementsByTagName("credentials").Item(0)

credentials.AppendChild(newElement)

doc.Save(Server.MapPath("../Web.config"))

lblResults.Text = "User saved. Username:" & _
strUsername & " Password:" & strHash

lblResults.Visible = True

txtPassword.Value = ""
txtUsername.Text = ""
End If

End Sub
End Class


<<<----- Return to Asp.Net Source Code Questions Page


Have a Question ? post your questions here. It will be answered as soon as possible.

Check Microsoft .Net Interview Questions for more Microsoft .Net Interview Questions with Answers.

Check .Net Database Interview Questions for more .Net Database Interview Questions with answers