【问题标题】:Is it possible to add a password to a child in Firebase?是否可以在 Firebase 中为孩子添加密码?
【发布时间】:2017-07-17 09:28:45
【问题描述】:

我正在创建一个包含用户可以加入和创建的频道的房间。但是,我希望用户可以选择为他们创建的频道添加密码。现在我想知道是否可以在 Firebase 中添加一个加密的密码。当然,一种选择是将密码上传到 Firebase 中的字符串中,就像普通值一样,但这对任何人都是可读的(因为 .read 规则说的是真的)。这样,任何人都可以看到我不想要的密码。所以我的问题是:这可能吗,如果是的话:如何?下面是一些可能会有所帮助的代码。

创建通道IBAction函数:

@IBAction func createChannel(_ sender: AnyObject) {
    if let name = newChannelTextField?.text {
        let newChannelRef = channelRef.childByAutoId()
        let channelItem = [
            "name": name
        ]
        newChannelRef.setValue(channelItem)
    }
}

Channel.swift:

internal class Channel {
    internal let id: String
    internal let name: String

    init(id: String, name: String) {
        self.id = id
        self.name = name
    }
}

是否选择了单元格功能:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
    {

        if indexPath.section == Section.currentChannelsSection.rawValue
        {
            if searchController.isActive && searchController.searchBar.text != ""
            {
                let channel = filteredChannels[(indexPath as NSIndexPath).row]
                sendStatisticsToChannel(channel: channel)
                     }
            else
            {
                let channel = channels[(indexPath as NSIndexPath).row]
                sendStatisticsToChannel(channel: channel)
            }
        }
    }

【问题讨论】:

    标签: swift firebase firebase-realtime-database firebase-authentication firebase-security


    【解决方案1】:

    不可以,除非您有服务器端来检查密码,或者您在 Firebase 规则中公开了密码。原因是为了检查用户输入的密码是否正确,必须对照实际密码进行检查。如果他们可以检查实际密码,那么他们可以从一开始就阅读它。加密也是如此。如果一切都在客户端完成,那么有人可能会扭转这个过程。

    【讨论】:

    • 好的,谢谢。您知道如何在设备上完成此操作吗?是否有加密扩展?谢谢!
    • 我不确定您使用的是什么设备,但如果您的加密算法在用户的设备上,它很可能会被破坏。您将需要一个服务器来使用加密或密码。您是否考虑过另一种方法?
    猜你喜欢
    • 1970-01-01
    • 2019-03-31
    • 1970-01-01
    • 2019-09-17
    • 2012-08-01
    • 1970-01-01
    • 2016-09-18
    • 1970-01-01
    • 2021-04-17
    相关资源
    最近更新 更多