<%@ Page Language="VB" autoeventwireup="true" %>
<HTML>
	<HEAD>
		<title>Hash password for storing in web.config file</title>
		<META content="NOINDEX,NOFOLLOW" name="ROBOTS">
		<META http-equiv="PRAGMA" content="NO-CACHE">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<script runat="server">
         Sub Cancel_Click(sender as Object, e as EventArgs )
            userName.Text = ""
            password.Text = ""
            repeatPassword.Text = ""
            result.Text = ""
         End Sub
    
         Sub HashPassword_Click(sender as Object, e as EventArgs)

               if string.compare(password.Text, repeatPassword.text, ignorecase:=true)<>0 then
					result.Text = "Password and repeated password are not equal!"
					exit sub
				end if
				
               Dim hashMethod As String
               If sha1.Checked Then
                  hashMethod = "SHA1"
               Else
                  hashMethod = "MD5"
               End If
    
               Dim hashedPassword As String
           hashedPassword =System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(password.Text, hashMethod)
	
               result.Text = "Replace in HTCOMNET\web.config file:<br>" + _
				  "&lt;add key=""ADMIN_NAME"" value=""Defaultvalue"" /&gt;<br>" + _
                  "&lt;add key=""ADMIN_PASSWORD"" value=""DefaultValue"" /&gt;<br><br>" + _ 
                  "with the text in textbox:<br>" + _ 
                  "<textarea name=""text"" cols=""90"" rows=""3"" readonly=""readonly"">&lt;add key=""ADMIN_NAME"" value=""" & userName.Text & """ /&gt;" + vbnewline + _
                  "&lt;add key=""ADMIN_PASSWORD"" value=""" & hashedPassword & """ /&gt;" + vbnewline + _ 
				  "&lt;add key=""ADMIN_PASSWORD_FORMAT"" value=""" & hashMethod & """ /&gt;</textarea>" 
				  
				  '"<br><br>or:<br><br>" + _  
				  '"&lt;add key=""HCADSI_USER_NAME"" value=""Defaultvalue"" /&gt;<br>" + _
                  '"&lt;add key=""HCADSI_USER_PASSWORD"" value=""DefaultValue"" /&gt;<br><br>" + _ 
                  '"with the text in textbox:<br>" + _ 
                  '"<textarea name=""text"" cols=""90"" rows=""3"" readonly=""readonly"">&lt;add key=""HCADSI_USER_NAME"" value=""" & userName.Text & """ /&gt;" + vbnewline + _
                  '"&lt;add key=""HCADSI_USER_PASSWORD"" value=""" & hashedPassword & """ /&gt;" + vbnewline + _ 
				  '"&lt;add key=""HCADSI_USER_PASSWORD_FORMAT"" value=""" & hashMethod & """ /&gt;</textarea>"

         End Sub
		</script>
	</HEAD>
	<body text="#ffffff" bgColor="#5a7dde">
			<strong><a href="adminpanel.aspx"><font color="#ffffff" size="3" face="Verdana, Arial, Helvetica, sans-serif">
					back to the Admin panel</font></a></strong><BR>
					
		<form id="Form1" runat="server">
			<p>This form displays the results of the 
				FormsAuthentication.HashPasswordForStoringInConfigFile method.</p>
			<table>
				<tbody>
					<tr>
						<td>New User Name:</td>
						<td><asp:TextBox id="userName" runat="server"></asp:TextBox></td>
					</tr>
					<tr>
						<td>Password:
						</td>
						<td><asp:TextBox id="password" runat="server" TextMode="Password"></asp:TextBox></td>
					</tr>
					<tr>
						<td>Repeat Password:
						</td>
						<td><asp:TextBox id="repeatPassword" runat="server" TextMode="Password"></asp:TextBox></td>
					</tr>
					<tr>
						<td>Hash function:
						</td>
						<td align="center"><asp:RadioButton id="sha1" runat="server" GroupName="HashType" Text="SHA1"></asp:RadioButton>
							<asp:RadioButton id="md5" runat="server" GroupName="HashType" Text="MD5"></asp:RadioButton></td>
					</tr>
					<tr>
						<td align="center" colspan="2">
							<asp:Button id="hashPassword" onclick="HashPassword_Click" runat="server" Text="Hash Password"></asp:Button>&nbsp;&nbsp;
							<asp:Button id="cancel" onclick="Cancel_Click" runat="server" Text="Cancel" CausesValidation="false"></asp:Button></td>
					</tr>
				</tbody>
			</table>
			<p><asp:Label id="result" runat="server"></asp:Label></p>
		</form>
	</body>
</HTML>
