Click here to Skip to main content
14,668,804 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi

How do I pass to my login form this received via Json?
// Class 1
public class ApiRest
{
  public string Message { get; set; }
  public string Status { get; set; }
}

// Class 2
public class ApiLogin
{
  public ApiRest Authenticate(string email, string passowrd)
  {
    var client = new RestClient("http://192.168.1.20/api/user/auth.php?email=" + email + "&password=" + passowrd);
    var response = client.Execute(new RestRequest());

    var authResponse = JsonConvert.DeserializeObject<apirest>(response.Content);
    return authResponse;
  }
}
I need to pass to my Windows form Login using text box, email, password and button login.

What I have tried:

I tried to create via constructor but my I cannot read strings email and password in my text boxes.

obs. php instance (auth.php) and site works.

Thanks
Posted
Updated 4-Jan-20 4:30am
v2
Comments
MadMyche 27-Dec-19 9:00am
   
You seem to be missing some code, such as what is in the RestRequest and where the username etc are coming from
Member 14382602 27-Dec-19 16:02pm
   
Coming from mysql data base. auth.php convert information to json

prepare("SELECT COUNT(*) FROM `users` WHERE `email` = :email AND `password` = :password");
$SQLCheckLogin -> execute(array(':email' => $email, ':password' => SHA1(md5($password))));
$countLogin = $SQLCheckLogin -> fetchColumn(0);
if (!($countLogin == 1))
{
echo json_encode(array("message" => "Authentication failed.", "status" => "failed"));
die();
}

echo json_encode(array("message" => "Authentication successful.", "status" => "success", "name" => $userInfo['nome']));

?>

Rate this:
Please Sign up or sign in to vote.

Solution 2

Oh dear. So little code, so many problems ...

1) You are hard coding yoru connection string: which means you have to change the code for production and release untested code. Always use a configuration file so the string is only recorded in a single place which is outside the app: that way your code doesn't change between dev and prod, and you don't have to "customise" each app for the environment it is going into.
2) You should also be aware that 192.168.x.x are local to a LAN, and are normally non-static. Which means that if your turn all the computers off for the weekend, they may very well all come back up with different IP addresses on Monday. Use Hostnames instead of IP addresses, even for local machines.
3) Never handle passwords as clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^]
And remember: if this is web based and you have any European Union users then GDPR applies and that means you need to handle passwords as sensitive data and store them in a safe and secure manner. Text is neither of those and the fines can be .... um ... outstanding. In December 2018 a German company received a relatively low fine of €20,000 for just that.
   
Rate this:
Please Sign up or sign in to vote.

Solution 1

Why arent you using ASP.NET Identity if you're using C#? It will create a database and controllers for all the usual functions
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100