Password hashing etc in Service Layer or Repositor

2019-04-10 01:55发布

As a matter of best practice in MVC, where should the logic go that deals with things such as password hashing/salting or data formatting before it gets sent to the database? I've read that the repository should only be used for logic that deals with data access. Is this something that belongs in a service layer? The controller? Does it even matter?

2条回答
聊天终结者
2楼-- · 2019-04-10 02:34

I'd be inclined to put the hashing in the repository layer, if only for the practical reason that you know if there's more than one service class that needs to store passwords, you'll have some assurance they don't do the hashing differently. Basically, follow the DRY principle.

查看更多
叼着烟拽天下
3楼-- · 2019-04-10 02:52

I think it depends on how you look at it. I'd be inclined to think of password hashing as something as necessary and therefore akin to, for example, escaping input before it goes to the database. In that case it would belong in the repository

查看更多
登录 后发表回答