Advertisement
Guest User

sign-up

a guest
May 22nd, 2016
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data.SqlClient;
  8. using System.Configuration;
  9. using System.Drawing;
  10. using System.Security.Cryptography;
  11. using Scrypt;
  12.  
  13. namespace WebApplication1
  14. {
  15. public partial class SignUp : System.Web.UI.Page
  16. {
  17. protected void Page_Load(object sender, EventArgs e)
  18. {
  19.  
  20.  
  21. }
  22.  
  23.  
  24.  
  25. protected void btSignup_Click(object sender, EventArgs e)
  26. {
  27. if (tbUname.Text != "" & tbPass.Text != "" && tbName.Text != "" && tbEmail.Text != "" && tbCPass.Text != "")
  28. {
  29. if (tbPass.Text == tbCPass.Text)
  30. {
  31. String CS = ConfigurationManager.ConnectionStrings["MyDatabaseConnectionString1"].ConnectionString;
  32. using (SqlConnection con = new SqlConnection(CS))
  33. {
  34. ScryptEncoder encoder = new ScryptEncoder();
  35. string hashsedPassword = encoder.Encode(tbPass.Text);
  36. SqlCommand cmd = new SqlCommand("insert into Users values('" + tbUname.Text + "','" + hashsedPassword + "','" + tbEmail.Text + "','" + tbName.Text + "')", con);
  37. con.Open();
  38. cmd.ExecuteNonQuery();
  39.  
  40. lblMsg.Text = "Registration Succesfull";
  41. lblMsg.ForeColor = Color.Green;
  42. Response.Redirect("~/SignIn.aspx");
  43. }
  44. }
  45. else { lblMsg.Text = "Passwords do not match"; }
  46. }
  47.  
  48. else
  49. {
  50. lblMsg.ForeColor = Color.Red;
  51. lblMsg.Text = "All Fields are Mandatory";
  52.  
  53. }
  54. }
  55.  
  56. protected void Button1_Click(object sender, EventArgs e)
  57. {
  58.  
  59. SqlConnection con1 = new SqlConnection();
  60. con1.ConnectionString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\MyDatabase.mdf;Integrated Security=True";
  61. con1.Open();
  62. SqlCommand cm1 = new SqlCommand();
  63. cm1.CommandText = "select * from [Users]where Username=@Uname";
  64. cm1.Parameters.AddWithValue("@Uname", tbUname.Text);
  65. cm1.Connection = con1;
  66. SqlDataReader rd = cm1.ExecuteReader();
  67. if (rd.HasRows)
  68. {
  69. Label1.Visible = true;
  70. Label1.Text = "Username already exists !";
  71. Label1.ForeColor = System.Drawing.Color.Red;
  72. }
  73.  
  74. else
  75. {
  76. Label1.Visible = true;
  77. Label1.Text = "Username is available !";
  78. Label1.ForeColor = System.Drawing.Color.Green;
  79. }
  80. }
  81.  
  82.  
  83. }
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement