I dont know if this question was asked before , i tried to find this
What is the best practice to implement an account Login function that returns an account object
while if the login is not success it would return the reason of failure (account is blocked,account need verification,account doesnt exist,….)
currently I use C# i implement something like this and just wanted to make sure if there is a better way
AccountBo resultAcc = null;
//this is the result account if sucessful login
LoginStatus ls = checkUserLogin(useerName, password, ref resultAcc);
//the return value is an enum with different possible statuses
Thanks in advance !
I would be terribly cautious to use the term “best practice”, not because of my suggestion, but because it is totally overused, but why not throw an exception (either carrying a status code member of type
LoginStatus, or using dedicated exceptions according to the specific error, or even a combination of both) in case the login fails?You then “have room” use the
AccountBoobject instance as return type.Premature “Anti Exceptions” comment:
Exceptions are often prematurely condemned these days (for dubious performance reasons). However, I would assume that any real world user/login check takes it’s share of CPU/cycles, so that working around exceptions is not really worth it.