使用 sfGuard 验证用户凭据

发布于 2024-12-23 04:25:21 字数 763 浏览 4 评论 0原文

我使用 symfony 1.4 和 sfGuard 以及 Propel,考虑到这是我第一次使用 symfony,我对架构的某些部分仍然是个菜鸟。

我被要求创建一些网络服务,其中之一是获取用户(电子邮件)和密码并打印出 json 字符串反馈作为结果。

我不知道如何使用 sfGuard 执行此类任务,因此如果有人有一个示例,我们将不胜感激。

我认为该算法应该是 sha1,因为在 sf_guard_user 表中我发现了类似的行

id  username                algorithm   salt                            password                                    created_at              last_login              is_active   is_super_admin
4   [email protected]   sha1    623de866b49c696b452e0d12b55895c8    dcbe87a60a769b9e3b5f0988141b824fa5206235    2011-12-06 02:32:43     2011-12-27 15:49:41     1           0

I use symfony 1.4 with sfGuard with Propel, and considering that this is my first symfony experience, I'm still a total noob with some part of the architecture.

I was asked to create some webservices, one of this shall be taking user (email) and password and print out a json string feedback as result.

I don't have a clue about how to perform such a task with sfGuard, so if anybody has an example it'd be appreciated.

I think that the algorithm should be sha1, because in the sf_guard_user table I found rows like

id  username                algorithm   salt                            password                                    created_at              last_login              is_active   is_super_admin
4   [email protected]   sha1    623de866b49c696b452e0d12b55895c8    dcbe87a60a769b9e3b5f0988141b824fa5206235    2011-12-06 02:32:43     2011-12-27 15:49:41     1           0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

兮子 2024-12-30 04:25:21

只需看一下 sfGuardValidatorUser 类即可。
基本上是这样的:

  1. 检查具有给定用户名的用户是否存在
  2. 如果 1. 然后检查它是否处于活动状态(is_active 字段)
  3. 如果 2. 然后使用 checkPassword 公共方法检查密码>sfGuardUser 类(默认类似于 sha1(db_salt.subscribed_pa​​ssword) == db_password

Just have a look at sfGuardValidatorUser class.
Basically it's something like this:

  1. Check if a user with the given username exists
  2. If 1. then check if it's active (is_active field)
  3. If 2. then check the password using the checkPassword public method from the sfGuardUser class (default is something like sha1(db_salt.submitted_password) == db_password)
流殇 2024-12-30 04:25:21

好吧,我发现了一个肮脏的伎俩,但它有效。

我可以伪造一个登录表单提交,然后按照通常的登录模式进行操作,它会变成这样:

        $request->setParameter('signin', array(
                'username' =>$request->getParameter("username"),
                'password' =>$request->getParameter("password"),
              ));
        $form = new BeetleLoginForm();
        $form->bind($request->getParameter('signin'));
        if ($form->isValid()) {
            $values = $form->getValues();
            $this->getUser()->signin($values['user'], false);
            $resp['return'] = "YES";
            $resp['message'] = "You have successfully logged in";
            return $this->renderText(json_encode($resp));

        }

我希望这可以帮助陷入同样困境的人。

Ok, I've found a dirty trick, but it works.

I can fake a login form submission and sitck to the usual login patter, which it becomes something like:

        $request->setParameter('signin', array(
                'username' =>$request->getParameter("username"),
                'password' =>$request->getParameter("password"),
              ));
        $form = new BeetleLoginForm();
        $form->bind($request->getParameter('signin'));
        if ($form->isValid()) {
            $values = $form->getValues();
            $this->getUser()->signin($values['user'], false);
            $resp['return'] = "YES";
            $resp['message'] = "You have successfully logged in";
            return $this->renderText(json_encode($resp));

        }

I hope that this could help somebody stuck in the same limbo.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文