Advertisement
Guest User

Untitled

a guest
May 22nd, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.76 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. using System;
  85. using System.Collections.Generic;
  86. using System.Linq;
  87. using System.Web;
  88. using System.Web.UI;
  89. using System.Web.UI.WebControls;
  90. using System.Data.SqlClient;
  91. using System.Configuration;
  92. using System.Data;
  93.  
  94. namespace WebApplication1
  95. {
  96. public partial class SignIn : System.Web.UI.Page
  97. {
  98. protected void Page_Load(object sender, EventArgs e)
  99. {
  100.  
  101. }
  102.  
  103.  
  104. protected void Button1_Click(object sender, EventArgs e)
  105. {
  106. String CS = ConfigurationManager.ConnectionStrings["MyDatabaseConnectionString1"].ConnectionString;
  107. using (SqlConnection con = new SqlConnection(CS)) {
  108. SqlCommand cmd= new SqlCommand("select * from Users where Username='"+ Username.Text+"' and Password='"+Password.Text+"'" , con);
  109. con.Open();
  110. SqlDataAdapter sda = new SqlDataAdapter(cmd);
  111. DataTable dt = new DataTable();
  112. sda.Fill(dt);
  113. if (dt.Rows.Count != 0)
  114. {
  115. Session["USERNAME "] = Username.Text;
  116. Response.Redirect("~/UserHome.aspx"); }
  117. else {
  118. lblError.Text = "Invalid Username or Password !";
  119.  
  120. }
  121. }
  122. }
  123. }
  124. }
  125.  
  126. ScryptEncoder encoder = new ScryptEncoder();
  127.  
  128. bool areEquals = encoder.Compare("mypassword", hashedPassword);
  129.  
  130. SqlCommand cmd = new SqlCommand("select * from Users where Username=@Username" , con);
  131. cmd.Parameters.Add("@Username", SqlDbType.NVarChar, 255, Username.Text);
  132.  
  133. con.Open();
  134. SqlDataAdapter sda = new SqlDataAdapter(cmd);
  135. DataTable dt = new DataTable();
  136. sda.Fill(dt);
  137. if (dt.Rows.Count != 0) {
  138. ScryptEncoder encoder = new ScryptEncoder();
  139.  
  140. foreach(DataRow row in dt.Rows)
  141. {
  142. if (encoder.Compare(Password.Text, row["Password"]))
  143. {
  144. Session["USERNAME "] = Username.Text;
  145. Response.Redirect("~/UserHome.aspx");
  146. return;
  147. }
  148. }
  149. } else {
  150. lblError.Text = "Invalid Username or Password !";
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement