Advertisement
Guest User

help

a guest
Jun 25th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASP 3.04 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;
  8. using System.Data.OleDb;
  9. using System.Data.SqlClient;
  10. using System.Security.Cryptography;
  11. using System.ComponentModel;
  12. using System.Text;
  13.  
  14. public partial class Register : System.Web.UI.Page
  15. {
  16.     protected void Page_Load(object sender, EventArgs e)
  17.     {
  18.         signUpFail.Visible = false;
  19.         signUpSuccess.Visible = false;
  20.         passwordFail.Visible = false;
  21.         DEBUGMESSAGE.Visible = false;
  22.     }
  23.  
  24.     protected void registerButton_Click(object sender, EventArgs e)
  25.     {
  26.         string IndvConnString = System.Configuration.ConfigurationManager.ConnectionStrings["LocalConnectionString"].ConnectionString;
  27.         OleDbConnection IndvSignCon = new OleDbConnection(IndvConnString);
  28.  
  29.         IndvSignCon.Open();
  30.  
  31.         Type csType = this.GetType();
  32.         // check to ensure that UserId keyed in is not being in used by other Customers
  33.         OleDbCommand cmd;
  34.         OleDbDataReader rdr;
  35.  
  36.         string strSQLSelect = "SELECT uEmail FROM Users ORDER BY uEmail";
  37.         cmd = new OleDbCommand(strSQLSelect, IndvSignCon);
  38.         rdr = cmd.ExecuteReader();
  39.  
  40.         while (rdr.Read())
  41.         {
  42.             if (email_textbox.Text == (string)rdr["uEmail"])
  43.             {
  44.                 signUpFail.Visible = true;
  45.                 IndvSignCon.Close();
  46.                 return;
  47.             }
  48.  
  49.             const int MIN_LENGTH = 10;
  50.  
  51.             string password = password_textbox.Text;
  52.  
  53.             if (password.Length < MIN_LENGTH)
  54.             {
  55.                 passwordFail.Visible = true;
  56.                 IndvSignCon.Close();
  57.                 return;
  58.             }
  59.  
  60.             string sSourceData;
  61.             byte[] tmpSource;
  62.             byte[] tmpHash;
  63.  
  64.             sSourceData = password_textbox.Text;
  65.  
  66.             tmpSource = ASCIIEncoding.ASCII.GetBytes(sSourceData);
  67.  
  68.             //Compute Hash
  69.             tmpHash = new MD5CryptoServiceProvider().ComputeHash(tmpSource);
  70.  
  71.             // insert new record
  72.             string strSQLInsert = "INSERT INTO "
  73.                 + " Users  (uName, uPass, uEmail, uNo, uEmerName, uEmerNo, uEmerRe)"
  74.                 + " VALUES (@name, @pw, @em, @hp, @emername, @emerhp, @emerrel)";
  75.  
  76.             cmd = new OleDbCommand(strSQLInsert, IndvSignCon);
  77.            
  78.             cmd.Parameters.AddWithValue("@name", name_textbox.Text);
  79.             cmd.Parameters.Add("@pw", OleDbType.VarBinary, 64).Value = tmpHash;
  80.             cmd.Parameters.AddWithValue("@em", email_textbox.Text);
  81.             cmd.Parameters.AddWithValue("@hp", phone_textbox.Text);
  82.             cmd.Parameters.AddWithValue("@emername", emerName_textbox.Text);
  83.             cmd.Parameters.AddWithValue("@emerhp", emerNo_textbox.Text);
  84.             cmd.Parameters.AddWithValue("@emerrel", emerRel_dropdown.Text);
  85.  
  86.             cmd.ExecuteNonQuery();
  87.             IndvSignCon.Close();
  88.  
  89.             signUpSuccess.Visible = true;
  90.  
  91.         }
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement