在我的iOS应用程序中,我试图允许用户使用他们当前在OpenCart系统中的用户信息登录到商店.如果我理解正确,则使用MD5加密密码.当我从应用程序加密密码时,它与数据库中存储的密码不匹配.有关为什么会这样的任何建议?关于如何解决它的任何建议?这是我第一次做过这类事情.
根据OpenCart的用户模型,密码加密比MD5更复杂:
public function addUser($data) { $this->db->query("INSERT INTO `" . DB_PREFIX . "user` SET username = '" . $this->db->escape($data['username']) . "', salt = '" . $this->db->escape($salt = substr(md5(uniqid(rand(), true)), 0, 9)) . "', password = '" . $this->db->escape(sha1($salt . sha1($salt . sha1($data['password'])))) . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', user_group_id = '" . (int)$data['user_group_id'] . "', status = '" . (int)$data['status'] . "', date_added = NOW()"); }
所以首先你生成这样的盐:
$salt = substr(md5(uniqid(rand(), true)), 0, 9);
然后你加密密码:
$password = sha1($salt . sha1($salt . sha1($data['password'])));