public async Task <OTP_Verified> verifyForgetPassword(UserOtpVerification userOtpObj) { OTP_Verified verification_status = new OTP_Verified(); verification_status.Verification_Result = false; bool otpValid = false; try { //connect to the Firebase Boolean connectionResult = connectToFirebase(); if (connectionResult) { DocumentReference docRef1 = db.Collection("UserKeys").Document(userOtpObj.Email_Address); DocumentSnapshot docSnap1 = await docRef1.GetSnapshotAsync(); DBUserKeys DBuserKeyObj = docSnap1.ConvertTo <DBUserKeys>(); var bytes = Encoding.ASCII.GetBytes(DBuserKeyObj.userKey); DateTime otp_obtained_time_from_user = System.DateTime.Now; //Comapre the otp obtained from the user if (otpString.Equals(userOtpObj.OTP.ToString())) { TimeSpan ts = otp_obtained_time_from_user - otp_generated_time; if (ts.TotalMinutes <= 2) { otpValid = true; verification_status.Verification_Result = true; } } } return(verification_status); } catch (Exception ex) { CustomException customException = new CustomException(); customException.errorTitleName = "Cannot Verify Your OTP ,Please Try Again later!!"; customException.errorMessageToUser = ex.Message; throw new FaultException <CustomException>(customException); } }
public async Task <OTP_Verified> verifyUser(UserOtpVerification userOtpObj) { OTP_Verified verification_status = new OTP_Verified(); try { //connect to the Firebase Boolean connectionResult = connectToFirebase(); if (connectionResult) { DocumentReference docRef1 = db.Collection("UserKeys").Document(userOtpObj.Email_Address); DocumentSnapshot docSnap1 = await docRef1.GetSnapshotAsync(); DBUserKeys DBuserKeyObj = docSnap1.ConvertTo <DBUserKeys>(); var bytes = Encoding.ASCII.GetBytes(DBuserKeyObj.userKey); bool otpValid = false; DateTime otp_obtained_time_from_user = System.DateTime.Now; //Comapre the otp obtained from the user if (otpString.Equals(userOtpObj.OTP.ToString())) { TimeSpan ts = otp_obtained_time_from_user - otp_generated_time; if (ts.TotalMinutes <= 2) { otpValid = true; } } //If OTP is verified then if (otpValid) { //update the Verification Status of the User on the Database DocumentReference docRef2 = db.Collection("User").Document(DBuserKeyObj.email); Dictionary <string, object> data2 = new Dictionary <string, object>() { { "verified", true }, }; //DocumentSnapshot docSnap2 = await docRef2.GetSnapshotAsync(); await docRef2.UpdateAsync(data2); verification_status.Verification_Result = true; //send the email for secure access Pin to the user await SendPDFEmail(PIN, user_Email, user_Password); //Create Encryption key for the user try { //This class create the encyrption key for the user for the further security features AzureEncryptDecrypt azureEncryptDecrypt = new AzureEncryptDecrypt(); string encryptionKeyName = await azureEncryptDecrypt.createEncryptionRSAKey(); DocumentReference documentReference_for_keys = db.Collection("UserEncryptionKeys").Document(userOtpObj.Email_Address); Dictionary <string, object> userKeyValues = new Dictionary <string, object>() { { "userEmailAddress", userOtpObj.Email_Address }, { "userKeyName", encryptionKeyName }, { "keyGenerationDate", DateTime.Now.ToString() } }; await documentReference_for_keys.SetAsync(userKeyValues); } catch (Exception ex) { //catch the exception and throw the error on the client CustomException customException = new CustomException(); customException.errorTitleName = ex.Message; customException.errorMessageToUser = "******"; throw new FaultException <CustomException>(customException); } return(verification_status); } } } catch (Exception ex) { //catch the exception and throw the error on the client CustomException customException = new CustomException(); customException.errorTitleName = ex.Message; customException.errorMessageToUser = "******"; throw new FaultException <CustomException>(customException); } //make false if the code reaches upto this verification_status.Verification_Result = false; //return the verification status to the user return(verification_status); }