Fixed two-factor authentication bug

Reverted back in master and made the same changes in development branch.
I think auto-merge is possible now. Also I felt this was a safer way because I wasn't sure if merging development and master might break something.