简体   繁体   English

使用Core PHP对Silverstripe用户进行身份验证

[英]Authenticate Silverstripe users using Core PHP

My client has a website and backend made with SilverStripe. 我的客户有一个使用SilverStripe制作的网站和后端。 Now the client wants a mobile app and for that he wants me to build an API to communicate with the database. 现在,客户需要一个移动应用程序,为此,他希望我构建一个API与数据库进行通信。 Unfortunately he wants me to use some other framework, or even a core PHP implementation with PDO. 不幸的是,他希望我使用其他框架,甚至是PDO的核心PHP实现。

My problem: 我的问题:

How does SilverStripe encrypt its password? SilverStripe如何加密密码? How do I manually authenticate users using plain PHP. 如何使用纯PHP手动验证用户。 Only the logic to encrypt/hash (like SilverStripe does) the user input will be enough for me. 对于我来说,仅用户输入的加密/哈希逻辑(如SilverStripe那样)就足够了。

Unfortunately he wants me to use some other framework, or even a core PHP implementation with PDO 不幸的是,他希望我使用其他框架,甚至是PDO的核心PHP实现。

You, as a developer, have the ability to tell your client why he might be wrong about this. 作为开发人员,您可以告诉您的客户为什么他对此有错。

If the website/application is built with SilverStripe then he should have a very good/specific reason not to continue to use it to implement an API over the top of the SilverStripe data - it makes perfect sense to use SilverStripe for this, and little sense to rewrite parts of the SilverStripe framework for the sake of "not using SilverStripe." 如果网站/应用程序是使用SilverStripe构建的,那么他应该有一个很好的/特定的原因,不要继续使用它来在SilverStripe数据之上实现API-为此,完全可以使用SilverStripe,这毫无意义为了“不使用SilverStripe”而重写SilverStripe框架的某些部分。

It's also important to mention to your client that the underlying encryption/hashing algorithms that SilverStripe implements are not part of its public API, and hence can change without requiring explicit notice given to developers. 还必须向您的客户提及SilverStripe实现的基础加密/哈希算法不是其公共API的一部分,因此可以更改而无需明确通知开发人员。 This could mean that the default algorithm could be changed (for example if a zero-day exploit is found in the blowfish algorithm) and your mobile app would then stop working. 这可能意味着可以更改默认算法(例如,如果在河豚算法中发现了零日漏洞利用),然后您的移动应用将停止工作。 Using a SilverStripe API would not have this same problem. 使用SilverStripe API不会有同样的问题。

The above also applies to the general data structure of SilverStripe. 上面的内容也适用于SilverStripe的常规数据结构。 Let's assume that one day they decide to move away from flat tables into an EAV database storage design - their public API (classes with public methods) will stay the same while their backend classes that separate the accessibility from the processing and data storage will change. 假设有一天他们决定从平面表转移到EAV数据库存储设计中-他们的公共API(带有公共方法的类)将保持不变,而将可访问性与处理和数据存储区分开的后端类将发生变化。 You will have to update your API too, if you build it yourself! 如果您自己构建API,那么您也将不得不更新您的API!

How does SilverStripe encrypt its passwords? SilverStripe如何加密密码?

It depends - the default method is encryption with the blowfish algorithm , but there are a half dozen or so (in 3.4.1) implementations of the PasswordEncryptor class that could be configured for use. 这取决于- 默认方法是使用河豚算法进行加密 ,但是可以配置使用PasswordEncryptor类的大约六个(在3.4.1中) 实现

The algorithm to use is configurable via the Security::$password_encryption_algorithm property, or via YAML config. 可通过Security::$password_encryption_algorithm属性或通过YAML配置来配置要使用的算法。

Each user could have a different password encryption/hashing algorithm used - take a look at the Member database table under the PasswordEncryption column. 每个用户可以使用不同的密码加密/哈希算法- 查看 PasswordEncryption列下的Member数据库表。

How do I manually authenticate users using plain PHP 如何使用纯PHP手动验证用户

Theoretically if you wanted to do this, you'd need to recreate most of the logic in the framework's authenticator. 从理论上讲,如果您想这样做,则需要在框架的身份验证器中重新创建大多数逻辑。 Start by looking at Member::checkPassword - this is the initiation of the logic to check the password against the member - which is what you'll care about. 首先查看Member::checkPassword这是针对该成员检查密码的逻辑的开始-这就是您要关心的问题。

You'll find yourself assuming that most implementations of SilverStripe will use the default algorithm of blowfish encryption, and follow PasswordEncryptor::create_for_algorithm through to PasswordEncryptor_Blowfish::check . 您会发现自己假设大多数SilverStripe实现都将使用默认的河豚加密算法,并遵循PasswordEncryptor::create_for_algorithmPasswordEncryptor_Blowfish::check At this point you'll see that you literally will end up replicating an amount of the SilverStripe framework's code to be able to achieve what you want. 此时,您将看到您最终将复制大量SilverStripe框架的代码以实现所需的功能。


Summary 摘要

  • What you want to achieve will involve a lot of duplication 您想要实现的目标将涉及很多重复
  • It will not work for 100% of SilverStripe implementations 它不适用于100%的SilverStripe实现
  • It may work now, but will break at some point when the algorithms change 它可能现在可以工作,但是在算法更改时会在某些时候中断
  • Ask your client why, and convince them to change their mind about it (after all, you're the expert, they're the client) 问您的客户为什么,并说服他们改变主意(毕竟,您是专家,他们是客户)
  • Use a SilverStripe API module (a couple listed below) 使用SilverStripe API模块(下面列出的几个)

API modules API模块

  • silverstripe/silverstripe-restfulserver - Officially supported, and provides a simple and easy way to get started with providing API access to your SilverStripe system. silverstripe/silverstripe-restfulserver官方支持,并且提供了一种简单易行的上手方式,提供对SilverStripe系统的API访问。 You have basic control over the HTTP request methods, and can limit access and permissions by each DataObject. 您具有对HTTP请求方法的基本控制,并且可以限制每个DataObject的访问和权限。
  • colymba/silverstripe-restfulapi - Community module. colymba/silverstripe-restfulapi社区模块。 Arguably more flexible and powerful. 可以说更加灵活和强大。 Slightly more work to set up/configure the way you want it to work. 设置/配置所需工作方式的工作要多一些。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM