Encoded Password Save in database | asp.net with c#
.aspx code (Design code):
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SaveEnc.aspx.cs" Inherits="test3.password_encrypt.SaveEnc" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1
{
width: 100%;
}
.auto-style2
{
text-align: right;
}
.auto-style3
{
text-align: left;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="auto-style1">
<tr>
<td class="auto-style2">
<asp:Label ID="Label1" runat="server" Text="Username : "></asp:Label>
</td>
<td class="auto-style3">
<asp:TextBox ID="UsernameTXT" runat="server" Width="244px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2">
<asp:Label ID="Label2" runat="server" Text="Password : "></asp:Label>
</td>
<td class="auto-style3">
<asp:TextBox ID="PasswordTXT" runat="server" OnTextChanged="PasswordTXT_TextChanged" TextMode="Password" Width="242px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2">
<asp:Label ID="lblmsg" runat="server"></asp:Label>
</td>
<td class="auto-style3">
<asp:Button ID="SaveB" runat="server" OnClick="SaveB_Click" Text="Save!!!" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
.aspx.cs code (Code behind):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Cryptography;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Compilation;
namespace test3.password_encrypt
{
public partial class SaveEnc : System.Web.UI.Page
{
SqlCommand cmd = new SqlCommand();
SqlConnection con = new SqlConnection();
static string Encrypt(string value)//for encryption of text
{
using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider())
{
UTF8Encoding utf8 = new UTF8Encoding();
byte[] data = md5.ComputeHash(utf8.GetBytes(value));
return Convert.ToBase64String(data);
}
}
protected void Page_Load(object sender, EventArgs e)
{
con.ConnectionString = ConfigurationManager.ConnectionStrings["constr1"].ConnectionString;
con.Open();
}
protected void SaveB_Click(object sender, EventArgs e)
{
try
{
SqlCommand cmd = new SqlCommand("insert into PassEnc" + "(Username,Password)values(@Username,@Password)", con);
cmd.Parameters.AddWithValue("@Username", UsernameTXT.Text);
cmd.Parameters.AddWithValue("@Password", PasswordTXT.Text);
cmd.ExecuteNonQuery();
lblmsg.Text = "--- New Account is created with Encrypted Password ---";
}
catch (SqlException ex)
{
if (ex.Number == 2627)
{
lblmsg.Text = "*** Username alredy exist ***";
}
else
{
lblmsg.Text = "An Error : " + ex.Message;
}
}
}
protected void PasswordTXT_TextChanged(object sender, EventArgs e)
{
PasswordTXT.Text = Encrypt(PasswordTXT.Text);
}
}
}
Casinos Near Bryson City NC - MapYRO
ReplyDeleteFind casinos 양주 출장안마 near 전라남도 출장샵 Bryson City NC, including Hampton Inn, 전주 출장안마 Fairfield 순천 출장샵 Inn, and Golden Nugget Casino. The following are 전라북도 출장샵 recommended properties that offer casino