Is there any way to do email confirmation for Firebase user creation and/or password reset?

前端 未结 9 2214
故里飘歌
故里飘歌 2020-11-28 04:03

Question says it all. In Firebase, how do I confirm email when a user creates an account, or, for that matter, do password reset via email.

I could ask more broadly:

9条回答
  •  难免孤独
    2020-11-28 05:05

    Update

    Note that this was never a very secure way of handling email verification, and since Firebase now supports email verification, it should probably be used instead.

    Original answer

    I solved the email verification using the password reset feature.

    On account creation I give the user a temporary (randomly generated) password. I then trigger a password reset which will send an email to the user with a link. The link will allow the user to set a new password.

    To generate a random password you can use code similar to this:

    function () {
      var possibleChars = ['abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!?_-'];
      var password = '';
      for(var i = 0; i < 16; i += 1) {
        password += possibleChars[Math.floor(Math.random() * possibleChars.length)];
      }
      return password;
    }
    

    Note that this is happening on the client, so a malicious user could tamper with your logic.

提交回复
热议问题