SignUpActivity.kt

		package com.example.firebaseloginkotlin
		
		import android.content.Intent
		import androidx.appcompat.app.AppCompatActivity
		import android.os.Bundle
		import android.util.Patterns
		import android.widget.Toast
		import com.example.firebaseloginkotlin.databinding.ActivitySignUpBinding
		import com.google.firebase.auth.FirebaseAuth
		import com.google.firebase.auth.ktx.auth
		import com.google.firebase.ktx.Firebase
		import java.util.regex.Pattern
		
		class SignUpActivity : AppCompatActivity() {
		
		    private lateinit var auth: FirebaseAuth
		    private lateinit var binding: ActivitySignUpBinding
		
		    override fun onCreate(savedInstanceState: Bundle?) {
		        super.onCreate(savedInstanceState)
		
		        binding = ActivitySignUpBinding.inflate(layoutInflater)
		        setContentView(binding.root)
		        auth = Firebase.auth
		
		        binding.signUpButton.setOnClickListener {
		
		            val mEmail = binding.emailEditText.text.toString()
		            val mPassword = binding.passwordEditText.text.toString()
		            val mRepeatPassword = binding.repeatPasswordEditText.text.toString()
		
		            val passwordRegex = Pattern.compile("^" +
		                    "(?=.*[‐@#$%^&+=])" +     // Al menos 1 car├ícter especial
		                    ".{6,}" +                // Al menos 4 caracteres
		                    "$")
		
		            if(mEmail.isEmpty() || !Patterns.EMAIL_ADDRESS.matcher(mEmail).matches()) {
		                Toast.makeText(this, "Ingrese un email valido.",
		                    Toast.LENGTH_SHORT).show()
		            } else if (mPassword.isEmpty() || !passwordRegex.matcher(mPassword).matches()){
		                Toast.makeText(this, "La contrase├▒a es debil.",
		                    Toast.LENGTH_SHORT).show()
		            } else if (mPassword != mRepeatPassword){
		                Toast.makeText(this, "Confirma la contrase├▒a.",
		                    Toast.LENGTH_SHORT).show()
		            } else {
		                createAccount(mEmail, mPassword)
		            }
		
		        }
		
		        binding.backImageView.setOnClickListener {
		            val intent = Intent(this, SignInActivity::class.java)
		            this.startActivity(intent)
		        }
		
		    }
		
		    public override fun onStart() {
		        super.onStart()
		        val currentUser = auth.currentUser
		        if(currentUser != null){
		            if(currentUser.isEmailVerified){
		                val intent = Intent(this, MainActivity::class.java)
		                this.startActivity(intent)
		            } else {
		                val intent = Intent(this, CheckEmailActivity::class.java)
		                this.startActivity(intent)
		            }
		        }
		    }
		
		    private fun createAccount(email: String, password: String) {
		        auth.createUserWithEmailAndPassword(email, password)
		            .addOnCompleteListener(this) { task ‐>
		                if (task.isSuccessful) {
		                    val intent = Intent(this, CheckEmailActivity::class.java)
		                    this.startActivity(intent)
		                } else {
		                    Toast.makeText(this, "No se pudo crear la cuenta. Vuelva a intertarlo",
		                        Toast.LENGTH_SHORT).show()
		                }
		            }
		    }
		
		}