Use database data for authentication

Asked

Viewed 148 times

1

I have a database with existing data, with name, CPF, RG and other personal data. I need to implement a login system, but I wanted the user to be in case the registration number and password CPF, for example. In the demonstrations of how to login, I am always told to make a new model with user and password. Then I ask, could use the same table from which I already have personal data to log in, or would have to copy the data from this table to a new model, dedicated only to the User?

What if I wanted to let the user log in with both email and registration number? How would I do this query?

  • You can do it, but the structure’s gonna get weird. I suggest you create a data migration routine, where it feeds the new login table with the existing data. If you choose to keep the data like this, how will you make the user change the password ? The User’s email is already present in the existing table?

  • Hello, Victor. Not yet, emails would only be available after users update their registration. What I still can’t understand is how to use the data in the presenta table to authenticate. Just copy the dafos of the columns I want to use to authenticate to the table created by the new model?

  • Doubt: In your application each registered person will be a user ?

  • Yes, each registered person is a user. They can log into the system to change their registration data.

  • Okay, in this case, it’s easier for you to create a password field, on that same table, and play the guy’s number to that field (by default), it’s up to you to encrypt that password or not. Take advantage and create together the email field. What do you think? Starting from this definition, what’s the next problem ?

  • That’s exactly what I was thinking about doing. Besides, if I copied the data to another model, to each registered associate, I would have to migrate the data. Anyway, I only have doubts about how to allow the username to be both the registration and the email.

Show 1 more comment

1 answer

0


In this case, it is easier to create a password field, in this same table, and play the guy’s CPF for this field (as default), it is up to you to encrypt this password or not. Use and create together the e-mail field

First do a validation on what the guy typed, with regex, with this you direct to e-mail validation or name. For Ruby validation, follow the link: https://stackoverflow.com/questions/22993545/ruby-email-validation-with-regex

From there the validation is normal. based on what you have for that record.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.