如何在flatter和Prestashop中登录
我在我的Flatter项目中使用PrestashopWeb服务,我可以获取和发布数据并注册客户,但我在登录时遇到了一个问题。 需要在Prestashop中登录才能散列密码以进行验证。 我尝试了很多类似散列的包,但都不起作用。 这是我的密码 //获取用户信息函数以获取密码如何在flatter和Prestashop中登录,rest,flutter,web-services,authentication,prestashop-1.7,Rest,Flutter,Web Services,Authentication,Prestashop 1.7,我在我的Flatter项目中使用PrestashopWeb服务,我可以获取和发布数据并注册客户,但我在登录时遇到了一个问题。 需要在Prestashop中登录才能散列密码以进行验证。 我尝试了很多类似散列的包,但都不起作用。 这是我的密码 //获取用户信息函数以获取密码 Future<List<Info>> getUserInfo(String email) async { var url = 'https://www.example.com/api/custom
Future<List<Info>> getUserInfo(String email) async {
var url =
'https://www.example.com/api/customers?filter[email]=$email&display=[id,lastname,firstname,passwd]';
List<Info> data = new List();
Response response;
response = await get(url, headers: <String, String>{
'authorization': getAuth(),
});
if (response.statusCode == 200) {
if (response.body.length != 0) {
var raw = XmlDocument.parse(response.body);
var elements = raw.findAllElements("customer");
data.addAll(elements.map((element) {
return Info(
customerID: removeAllHtmlTags(
element.findElements('id').single.text.toString()),
firstName: removeAllHtmlTags(
element.findElements('lastname').single.text.toString()),
lastName: removeAllHtmlTags(
element.findElements('firstname').single.text.toString()),
password: removeAllHtmlTags(
element.findElements('passwd').single.text.toString()),
);
}).toList());
} else {
data = null;
}
}
return data;}
Future getUserInfo(字符串电子邮件)异步{
变量url=
'https://www.example.com/api/customers?filter[email]=$email&display=[id,lastname,firstname,passwd];
列表数据=新列表();
反应;
响应=等待获取(url、标题:{
“授权”:getAuth(),
});
如果(response.statusCode==200){
if(response.body.length!=0){
var raw=XmlDocument.parse(response.body);
var要素=原始财务要素(“客户”);
data.addAll(elements.map)((element){
返回信息(
customerID:删除所有HTMLTAGS(
element.findElements('id').single.text.toString()),
名字:removeAllHtmlTags(
element.findElements('lastname').single.text.toString()),
姓氏:removeAllHtmlTags(
element.findElements('firstname').single.text.toString()),
密码:removeAllHtmlTags(
element.findElements('passwd').single.text.toString(),
);
}).toList());
}否则{
数据=空;
}
}
返回数据;}
////验证登录
Future<String> VerifyLogin({String password, String email}) async {
String result = '';
List<Info> data = await getUserInfo(email);
const cookie_key = '$cookie_key';
final cryptPass = crypto.md5
.convert(utf8.encode(cookie_key + password))
.toString()
.toLowerCase();
if (data != null) {
print(cryptPass);
print(data.first.password);
if (data.first.password == cryptPass) {
final SharedPreferences prefs = await _prefs;
prefs.setString('id', data.first.customerID);
result = 'success';
} else {
result = 'wrong password';
}
} else {
result = 'wrong email';
}
return result;}
Future VerifyLogin({String password,String email})异步{
字符串结果=“”;
列表数据=等待getUserInfo(电子邮件);
const cookie_key=“$cookie_key”;
最终密码传递=crypto.md5
.convert(utf8.encode(cookie_键+密码))
.toString()
.toLowerCase();
如果(数据!=null){
打印(密码通行证);
打印(数据.第一.密码);
if(data.first.password==cryptPass){
最终共享优先权=等待优先权;
prefs.setString('id',data.first.customerID);
结果=‘成功’;
}否则{
结果='密码错误';
}
}否则{
结果='错误的电子邮件';
}
返回结果;}
正在使用Prestashop 1.7 bcrypt中的
请参阅答案,它完美地解释了Prestashop如何处理密码加密/哈希。我看到了这个答案,但问题是我没有在CRYPT_BLOWFISH算法中找到加密密码的包,请查看此文档