ServiceReference1.Service1Client logIn = new ServiceReference1.Service1Client(); logIn.SaltReturnCompleted += new EventHandler<SaltReturnCompletedEventArgs>(logIn_SaltReturnCompleted); logIn.SaltReturnAsync(tBoxUName.Text); private void logIn_SaltReturnCompleted(object sender, SaltReturnCompletedEventArgs e) { //this.salt = (string)e.Result; tBlockError.Text = (string)e.Result; tBlockError.Visibility = Visibility.Visible; }
<connectionStrings> <add name="DBConnectionString" connectionString="Data Source=adress to server withheld for security;Initial Catalog=database name withheld for security;Username=withheld for security;Password=withheld for security"/> </connectionStrings>
[OperationContract] public string SaltReturn(string tempUser) { string tempSalt = ""; ArrayList salt = new ArrayList(); using (SqlConnection con = new SqlConnection()) { // Configure the SqlConnection object's connection string. con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString; // Open the database connection. try { con.Open(); }//closes try. catch (Exception) { }//closes catch. if (con.State == ConnectionState.Open) { try { SqlCommand command = new SqlCommand("SELECT salt FROM bvtvweb_user WHERE (username = '" + tempUser + "');", con); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { tempSalt = reader.GetString(0); salt.Add(tempSalt); }//closes while. reader.Close(); }//closes try. catch (Exception) { }//closes catch. if (salt.Contains(tempSalt)) { }//closes if. else { tempSalt = ""; }//closes else. }//closes if. }//closes using. return tempSalt; }//closes method.