title: How to generate unique random alphanumeric tokens in Golang?
body: <p>For a RESTful backend API, I want to generate <strong>unique</strong> url tokens to be used to authenticate users. </p>
  
  <p>The unique data provided at registration to generate tokens are email addresses. But after generating tokens and sending that to the users, I don't need to decrypt received tokens to get email or other information. So the encryption can be one-way.</p>
  
  <p>Initially I used bcrypt to do so:</p>
  
  <pre><code>func GenerateToken(email string) string {
      hash, err := bcrypt.GenerateFromPassword([]byte(email), bcrypt.DefaultCost)
      if err != nil {
          log.Fatal(err)
      }
      fmt.Println("Hash to store:", string(hash))
  
      return string(hash)
  
  }
  </code></pre>
  
  <p>But since the tokens come as a url parameter (like <code>/api/path/to/{token}</code>) I can not use <a href="https://godoc.org/golang.org/x/crypto/bcrypt" rel="noreferrer">bcrypt</a> because it generates tokens containing <code>/</code> like this:</p>
  
  <p><code>"$2a$10$NebCQ8BD7xOa82nkzRGA9OEh./zhBOPcuV98vpOKBKK6ZTFuHtqlK"</code></p>
  
  <p>which will break the routing. </p>
  
  <p>So I'm wondering what is the best way to generate some unique 16-32 character alphanumeric tokens based on emails in Golang?</p>