0

我正在爲用戶可以加入和創建的頻道創建一個空間。但是,我希望用戶給出一個選項來爲他們創建的頻道添加密碼。現在我想知道是否可以在加密的Firebase中添加密碼。當然,一種選擇是將密碼作爲正常值上傳到Firebase中的字符串中,但任何人都可以讀取(因爲.read規則爲真)。這樣,任何人都可以看到不是我想要的密碼。所以我的問題是:這是可能的,如果是的話:如何?以下是一些可能有所幫助的代碼。是否可以在Firebase中向孩子添加密碼?

創建頻道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) 
      } 
     } 
    } 

回答

1

不,除非你有一個服務器端的檢查密碼或您在Firebase規則中公開密碼。原因是爲了檢查用戶是否輸入了正確的密碼,必須根據實際密碼進行檢查。如果他們可以檢查實際的密碼,那麼他們可以讀取它開始。加密也是一樣。如果一切都在客戶端完成,那麼有人可能會改變流程。

+0

好的,謝謝。你有什麼想法如何做到這一點在設備上?是否有加密擴展?謝謝! – Petravd1994

+0

我不確定你在使用什麼設備,但最有可能的情況是,如果你的加密算法在用戶設備上可以被破壞。您將需要一臺服務器來使用加密或密碼。你有沒有考慮另一種方法? –

相關問題