public UserCookie ValidateUser(string phoneNumber, int oneTimePassword, string deviceId, string random) { string normalizedPhone = PhoneNumberUtils.ValidatePhoneNumber(phoneNumber); User existingUser = UserDbQuery.Instance.GetUserFromPhone(normalizedPhone); if (existingUser == null) { throw new Exception("User not registered"); } Authenticator.TOTP oneTimePasswordValidator = new Authenticator.TOTP(existingUser.UserData.Secret, 30, 6); if (!oneTimePasswordValidator.Verify(oneTimePassword)) { throw new Exception("Invalid one-time password"); } UserCookie cookie = UserCookie.GetCookie(existingUser.UserData, deviceId); if (cookie == null) { cookie = UserCookie.CreateCookie(existingUser.UserData, deviceId); } else { cookie.Update(); } return(cookie); }
public UserCookie ValidateUser(string phoneNumber, int oneTimePassword, string deviceId, string random) { string normalizedPhone = PhoneNumberUtils.ValidatePhoneNumber(phoneNumber); User existingUser = UserDbQuery.Instance.GetUserFromPhone(normalizedPhone); if (existingUser == null) { throw new Exception("User not registered"); } Authenticator.TOTP oneTimePasswordValidator = new Authenticator.TOTP(existingUser.UserData.Secret, 30, 6); if (!oneTimePasswordValidator.Verify(oneTimePassword)) { throw new Exception("Invalid one-time password"); } UserCookie cookie = UserCookie.GetCookie(existingUser.UserData, deviceId); if (cookie == null) { cookie = UserCookie.CreateCookie(existingUser.UserData, deviceId); } else { cookie.Update(); } return cookie; }
private void SendSmsWithConfirmationCode(DAL.User user) { // Task.Factory.StartNew(() => { Authenticator.TOTP oneTimePasswordValidator = new Authenticator.TOTP(user.Secret, 30, 6); int code = oneTimePasswordValidator.Now(); Authenticator.SmsSender sender = new Authenticator.SmsSender(); sender.SendSMS(user.PhoneNumber, code); }//); }
/// <summary> /// Validates the one-time password for the user /// </summary> /// <param name="phoneNumber"></param> /// <param name="cookie"></param> /// <returns></returns> public DAL.UserCookie ValidateUser(string phoneNumber, int oneTimePassword, string deviceId, string random) { string normalizedPhone = DAL.PhoneNumberUtils.ValidatePhoneNumber(phoneNumber); DAL.User existingUser = DAL.UserService.Instance.GetUserFromPhone(normalizedPhone); if (existingUser == null) { throw new Exception("User not registered"); } Authenticator.TOTP oneTimePasswordValidator = new Authenticator.TOTP(existingUser.Secret, 30, 6); if (!oneTimePasswordValidator.Verify(oneTimePassword)) { throw new Exception("Invalid one-time password"); } DAL.UserService.Instance.UpdateDeviceId(existingUser, deviceId); DAL.UserCookie cookie = new DAL.UserCookie(existingUser, deviceId); return(cookie); }
private void SendSmsWithConfirmationCode(DAL.User user) { // Task.Factory.StartNew(() => { Authenticator.TOTP oneTimePasswordValidator = new Authenticator.TOTP(user.Secret, 30, 6); int code = oneTimePasswordValidator.Now(); Authenticator.SmsSender sender = new Authenticator.SmsSender(); sender.SendSMS(user.PhoneNumber, code); }//); }
/// <summary> /// Validates the one-time password for the user /// </summary> /// <param name="phoneNumber"></param> /// <param name="cookie"></param> /// <returns></returns> public DAL.UserCookie ValidateUser(string phoneNumber, int oneTimePassword, string deviceId, string random) { string normalizedPhone = DAL.PhoneNumberUtils.ValidatePhoneNumber(phoneNumber); DAL.User existingUser = DAL.UserService.Instance.GetUserFromPhone(normalizedPhone); if (existingUser == null) { throw new Exception("User not registered"); } Authenticator.TOTP oneTimePasswordValidator = new Authenticator.TOTP(existingUser.Secret, 30, 6); if (!oneTimePasswordValidator.Verify(oneTimePassword)) { throw new Exception("Invalid one-time password"); } DAL.UserService.Instance.UpdateDeviceId(existingUser, deviceId); DAL.UserCookie cookie = new DAL.UserCookie(existingUser, deviceId); return cookie; }