public UCSUser GetStudent(string email) { UCSUser ucsuser = new UCSUser(); string user = "******"; string password = "******"; SqlConnection BAIS3150 = new SqlConnection(); BAIS3150.ConnectionString = @$ "Persist Security Info=False;Database={user};User ID={user};Password={password};server=dev1.baist.ca;"; BAIS3150.Open(); SqlCommand ASampleCommand = new SqlCommand { Connection = BAIS3150, CommandType = CommandType.StoredProcedure, CommandText = "GetUser", }; SqlParameter ASampleCommandParameter = new SqlParameter { ParameterName = "@Email", SqlDbType = SqlDbType.VarChar, Direction = ParameterDirection.Input, SqlValue = email }; ASampleCommand.Parameters.Add(ASampleCommandParameter); SqlDataReader ASampleDataReader; ASampleDataReader = ASampleCommand.ExecuteReader(); if (ASampleDataReader.HasRows) { Console.WriteLine("Columns:"); Console.WriteLine("--------"); for (int index = 0; index < ASampleDataReader.FieldCount; index++) { Console.WriteLine(ASampleDataReader.GetName(index)); } Console.WriteLine("Values:"); Console.WriteLine("-------"); while (ASampleDataReader.Read())// no value no read (returns true until no rows left to return) { for (int i = 0; i < ASampleDataReader.FieldCount; i++) { Console.WriteLine(ASampleDataReader.GetValue(i)); ucsuser.Email = email; ucsuser.UserName = (string)ASampleDataReader["UserName"]; ucsuser.HashPass = (string)ASampleDataReader["HashPass"]; ucsuser.SaltPass = (string)ASampleDataReader["SaltPass"]; ucsuser.Role = (string)ASampleDataReader["Role"]; ucsuser.Created = (DateTime)ASampleDataReader["Created"]; } } BAIS3150.Close(); } BAIS3150.Close(); return(ucsuser); }
public async Task <IActionResult> OnPost() { string uiEmail = Email; string uiPassword = Password; UCSUser ucsuser = new UCSUser(); string user = "******"; string password = "******"; SqlConnection BAIS3150 = new SqlConnection(); BAIS3150.ConnectionString = @$ "Persist Security Info=False;Database={user};User ID={user};Password={password};server=dev1.baist.ca;"; BAIS3150.Open(); SqlCommand ASampleCommand = new SqlCommand { Connection = BAIS3150, CommandType = CommandType.StoredProcedure, CommandText = "GetUser", }; SqlParameter ASampleCommandParameter = new SqlParameter { ParameterName = "@Email", SqlDbType = SqlDbType.VarChar, Direction = ParameterDirection.Input, SqlValue = uiEmail }; ASampleCommand.Parameters.Add(ASampleCommandParameter); SqlDataReader ASampleDataReader; ASampleDataReader = ASampleCommand.ExecuteReader(); if (ASampleDataReader.HasRows) { Console.WriteLine("Columns:"); Console.WriteLine("--------"); for (int index = 0; index < ASampleDataReader.FieldCount; index++) { Console.WriteLine(ASampleDataReader.GetName(index)); } Console.WriteLine("Values:"); Console.WriteLine("-------"); while (ASampleDataReader.Read())// no value no read (returns true until no rows left to return) { for (int i = 0; i < ASampleDataReader.FieldCount; i++) { // Console.WriteLine(ASampleDataReader.GetValue(i)); ucsuser.Email = uiEmail; ucsuser.UserName = ASampleDataReader.GetValue("UserName").ToString(); ucsuser.HashPass = ASampleDataReader.GetValue("HashPass").ToString(); ucsuser.SaltPass = ASampleDataReader.GetValue("SaltPass").ToString(); ucsuser.Role = ASampleDataReader.GetValue("Role").ToString(); ucsuser.Created = DateTime.Parse(ASampleDataReader.GetValue("Created").ToString()); } } BAIS3150.Close(); } BAIS3150.Close(); // Convert a C# string to a byte array // byte[] bytes = Encoding.ASCII.GetBytes(ucsuser.HashPass); // foreach (byte b in bytes) // { // Console.WriteLine(b); // } Message = $"${ucsuser.Role}{ucsuser.Email} {ucsuser.HashPass} :"; Console.WriteLine(); // Convert a C# string to a byte array if (Email == ucsuser.Email) { if (CheckMatch(ucsuser.HashPass, uiPassword)) { var claims = new List <Claim> { new Claim(ClaimTypes.Email, ucsuser.Email), new Claim(ClaimTypes.Name, ucsuser.UserName) }; var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); claimsIdentity.AddClaim(new Claim(ClaimTypes.Role, ucsuser.Role)); AuthenticationProperties authProperties = new AuthenticationProperties { }; await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity), authProperties); return(RedirectToPage("/Admin/Index")); } } // Message = "Invalid Attempt"; return(Page()); }