Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data.SqlClient;
- using System.Configuration;
- using System.Drawing;
- using System.Security.Cryptography;
- using Scrypt;
- namespace WebApplication1
- {
- public partial class SignUp : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void btSignup_Click(object sender, EventArgs e)
- {
- if (tbUname.Text != "" & tbPass.Text != "" && tbName.Text != "" && tbEmail.Text != "" && tbCPass.Text != "")
- {
- if (tbPass.Text == tbCPass.Text)
- {
- String CS = ConfigurationManager.ConnectionStrings["MyDatabaseConnectionString1"].ConnectionString;
- using (SqlConnection con = new SqlConnection(CS))
- {
- ScryptEncoder encoder = new ScryptEncoder();
- string hashsedPassword = encoder.Encode(tbPass.Text);
- SqlCommand cmd = new SqlCommand("insert into Users values('" + tbUname.Text + "','" + hashsedPassword + "','" + tbEmail.Text + "','" + tbName.Text + "')", con);
- con.Open();
- cmd.ExecuteNonQuery();
- lblMsg.Text = "Registration Succesfull";
- lblMsg.ForeColor = Color.Green;
- Response.Redirect("~/SignIn.aspx");
- }
- }
- else { lblMsg.Text = "Passwords do not match"; }
- }
- else
- {
- lblMsg.ForeColor = Color.Red;
- lblMsg.Text = "All Fields are Mandatory";
- }
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- SqlConnection con1 = new SqlConnection();
- con1.ConnectionString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\MyDatabase.mdf;Integrated Security=True";
- con1.Open();
- SqlCommand cm1 = new SqlCommand();
- cm1.CommandText = "select * from [Users]where Username=@Uname";
- cm1.Parameters.AddWithValue("@Uname", tbUname.Text);
- cm1.Connection = con1;
- SqlDataReader rd = cm1.ExecuteReader();
- if (rd.HasRows)
- {
- Label1.Visible = true;
- Label1.Text = "Username already exists !";
- Label1.ForeColor = System.Drawing.Color.Red;
- }
- else
- {
- Label1.Visible = true;
- Label1.Text = "Username is available !";
- Label1.ForeColor = System.Drawing.Color.Green;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement