在服务层或存储库的密码哈希等? [英] Password hashing etc in Service Layer or Repository?

查看:158
本文介绍了在服务层或存储库的密码哈希等?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为MVC的最佳实践的问题,应该在哪里逻辑去,与东西,如密码哈希/盐腌或数据格式的交易之前被发送到数据库?我读过库应该只用于与数据访问逻辑交易。这是不是在一个服务层属于?该控制器?它甚至关系呢?

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?

推荐答案

我倾向于把散列存储库中的层,如果只是为了你知道,如果有一个以上的服务类,需要在实践理性存储密码,你就会有一些保证他们不这样做的哈希不同。基本上,按照 DRY原则

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.

这篇关于在服务层或存储库的密码哈希等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆