我正在创建一个包含用户可以加入和创建的频道的房间。但是,我希望用户可以选择为他们创建的频道添加密码。现在我想知道是否可以在加密的Firebase中添加密码。当然,一个选项是将密码作为普通值上传到Firebase中的字符串,但任何人都可以读取(因为.read规则为true)。这样,任何人都可以看到不是我想要的密码。所以我的问题是:这是可能的,如果是的话:怎么样?以下是一些可能有用的代码。
创建频道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)
}
}
}
答案 0 :(得分:1)
不,除非您有服务器端检查密码或在Firebase规则中公开密码。原因是为了检查用户是否输入了正确的密码,必须根据实际密码进行检查。如果他们可以检查实际密码,那么他们可以开始阅读它。加密也是如此。如果一切都在客户端完成,那么有人可以撤销该过程。