BabaOrhum Posted March 4, 2019 Share Posted March 4, 2019 I would login Prestashop user from an external web application (developed in c#) and then redirect him to my Prestashop as a connected user. My approach consist in a POST HTTP call to the ‘authentication’ controller of the Prestashop with this parameters and theirs respective values: email à [email protected] passwd à hash in MD5 back à my-account SubmitLogin à true The HTTP response is OK, but when it redirect to the Prestashop, the user isn’t connected. I understand that a cookie is necessary to auto connect, but I don’t know how to get it. So I have two questions: Is my approach correct ? How to implement the cookie in my code ? My current code is as bellow: protected void BoutonAuthentificationPrestashop_Click(object sender, EventArgs e) { try { var request = (HttpWebRequest)WebRequest.Create("https://www.flexmarket.fr/index.php?controller=authentication"); var postData = string.Format("email={0}&passwd={1}&back={2}&SubmitLogin=1", "[email protected]", MD5Hash("xxxxxxx"), "my-account"); var data = Encoding.ASCII.GetBytes(postData); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = data.Length; using (var stream = request.GetRequestStream()) { stream.Write(data, 0, data.Length); } var res = (HttpWebResponse)request.GetResponse(); Page.Response.Write("<script>window.open('" + res.ResponseUri.AbsoluteUri + "','_blank');</script>"); } catch (Exception ex) { } } public static string MD5Hash(string input) { StringBuilder hash = new StringBuilder(); MD5CryptoServiceProvider md5provider = new MD5CryptoServiceProvider(); byte[] bytes = md5provider.ComputeHash(new UTF8Encoding().GetBytes(input)); for (int i = 0; i < bytes.Length; i++) { hash.Append(bytes[i].ToString("x2")); } return hash.ToString(); } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now