updating 2 unique item in data base

hello
50 Replies
NIMA
NIMA4d ago
my user name and phone number in data base in unique now i made a part so it can be updated but if the user name and phone number be same as old one it cant update the password and for update password user need to chenge the username + phone number everytime
NIMA
NIMA4d ago
is there anyway i can fix it
ἔρως
ἔρως4d ago
yes: separate the password update it makes absolutely no sense to send a password update at the same time you send phone number updates so, create a separated form for the password
NIMA
NIMA4d ago
should i do this for user name and phone number too ? or only password
ἔρως
ἔρως4d ago
usernames should have a separated system too, since they MUST be unique
NIMA
NIMA4d ago
but over all it is possibel do to all of the at once ?
ἔρως
ἔρως4d ago
DO NOT DO THEM AT ONCE
NIMA
NIMA4d ago
yes but in overall i mean
ἔρως
ἔρως4d ago
it is, but it is very bad ux the password needs to be updated separatedly
NIMA
NIMA4d ago
im making another section for it
ἔρως
ἔρως4d ago
here's the correct process to update a password: - check if all fields are filled in - check if the new password and confirmation are the same - check if it respects the rules you want for the password - check if the password hash matches the hash in the database - update the hash in the database or reject just check how other websites do it many even have an entirely different page just for the password
NIMA
NIMA4d ago
ye most of them use diffrent page i just remove editing username and only phone number
ἔρως
ἔρως4d ago
you should give the option of having a display name that isnt an username, like how discord does
NIMA
NIMA4d ago
thats a good idea
ἔρως
ἔρως4d ago
and obviously, store emails too if you need to update the email address or username or restore passwords, you need an email address
NIMA
NIMA4d ago
in first i was gonna only use phone number and no password and user name and only people can enter website with 2fa but i chenge it to this
ἔρως
ἔρως4d ago
you mean, with oauth?
NIMA
NIMA4d ago
yes
ἔρως
ἔρως4d ago
then it isnt 2fa if it only uses oauth
NIMA
NIMA4d ago
hmm
ἔρως
ἔρως4d ago
but that is a good idea, as you dont have to deal with passwords
NIMA
NIMA4d ago
yes thats very eazyer and faster
ἔρως
ἔρως4d ago
and im pretty sure you will royally screw it, as dealing with passwords is hard i mean, if you're asking about how to update a password, im sure you arent using hashes
NIMA
NIMA4d ago
yes
ἔρως
ἔρως4d ago
are you using hashes?
NIMA
NIMA4d ago
NO
ἔρως
ἔρως4d ago
then you're doing it very very very very wrong
NIMA
NIMA4d ago
..... it is very importent ?
ἔρως
ἔρως4d ago
lets put it this way: if you dont want to be on the news for a data leak, it is mandatory
NIMA
NIMA4d ago
🤣 i can do it with only php ?
ἔρως
ἔρως4d ago
yes, use password_hash and the associated functions
NIMA
NIMA4d ago
and i need to un hash it for using it ?
ἔρως
ἔρως4d ago
you cant unhash it thats the whole point of the hash: it's always one way
NIMA
NIMA4d ago
but system will un hash it for using it ?
ἔρως
ἔρως4d ago
no there is no unhashing it doesnt exist
NIMA
NIMA4d ago
if someone get the hashed password some how he can just login into account
ἔρως
ἔρως4d ago
unless the hashing algorithm is broken and insecure no, because the hash of it will be different
NIMA
NIMA4d ago
is php hashing system safe?
ἔρως
ἔρως4d ago
it's safe enough, as far as we know today and as far as has been mathematically proven so far
Jochem
Jochem4d ago
any password you put into a hash will always produce the same hash (with some caveats, but not going to go into that here). So when someone logs in, you send the password to the server, which then calculates the hash of the sent password and compares it to the hash in the database. If they match, what the user put in matches what they put in when they last changed their password
ἔρως
ἔρως4d ago
yup, but you need to use a specific function to compare, or your site is susceptible to timming attacks and php has weirdness when comparing strings with numbers too ... and you need to re-hash the password if the setting have changed as well but as jochem explained, you always hash the value to compare to the password
Jochem
Jochem4d ago
basically, "it's complicated" and it's a good idea to read up on best practices before you ever use this for something even remotely important, and probably before you write any code that you'd want to show anyone else and never, ever, EVER use passwords without hashing. Not even once I've had to maintain an application from when MD5 was fine through SHA1 and up to using mcrypt and finally password_hash. It's not the end of the world, you just check the type of hash, validate with that one, and update the hash if it's valiid to the newest type on next login. And invalidate any passwords using the old hash six months after the transition
ἔρως
ἔρως4d ago
ive had to do the same, and it was a little messy but still, you have to compare the hash in a timming-constant way and not use the == operator the === is fine, but isnt timming-constant
Jochem
Jochem4d ago
back in the day, I just decided that 700ms was an acceptable response time, logged the start, then never returned anything from the page until 700ms had passed no matter what the outcome of the password check was
ἔρως
ἔρως4d ago
no, no, that's not what i meant it's to prevent timming attacks for example, the time that a wrong input takes is different from the correct one with that, and many attempts, it is possible to guess the password (specially if it isnt even hashed)
Jochem
Jochem4d ago
yeah, that's what I mean. I saved the start time in a variable, checked the password, then if it was successful loaded everything from the DB and set everything up serverside. That always took <50ms. Then, whether the check succeeded or not, I subtracted the start time from the current time, subtracted that result from 700, and slept for that many ms before the first output to apache ever took place it's crude, but there wasn't anything built in back then anyway, this is just two old developers rambling on about how shit used to work "back in our day 🧓"
ἔρως
ἔρως4d ago
that is a very very shoddy and consistent way of doing it it's smart, not gonna lie
Jochem
Jochem4d ago
I mean, this was PHP4 days so shoddy was the way you did everything
ἔρως
ἔρως4d ago
yeah, it's understandable
Want results from more Discord servers?
Add your server