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);
        }
        public async Task <bool> sendOTP(string email, string userName, bool isForgetPassword)
        {
            try
            {
                //Connec to the Firestore Database
                Boolean connectionResult = connectToFirebase();
                //Create the instance to the document refernce and get to the path of the user document
                DocumentReference docRef1 = db.Collection("UserKeys").Document(email);
                //Snapshot for the same document
                DocumentSnapshot docSnap1 = await docRef1.GetSnapshotAsync();

                //Get the User Secret Keys
                DBUserKeys DBuserKeyObj = docSnap1.ConvertTo <DBUserKeys>();

                //var bytes= Base32Encoding.ToBytes(DBuserKeyObj.userKey);
                var bytes = Encoding.ASCII.GetBytes(DBuserKeyObj.userKey);
                //Creating otp
                var TotpObj = new Totp(bytes, step: 120);
                otpString          = TotpObj.ComputeTotp();
                otp_generated_time = System.DateTime.Now;
                //sending otp using email
                string      emailAddress = System.Configuration.ConfigurationManager.AppSettings["SecureDeskEmailAddress"];
                MailMessage mailMessage  = new MailMessage(emailAddress, email);


                //Get the connection string from the azure
                string connection_String = System.Configuration.ConfigurationManager.AppSettings["SecureDeskConnectionStringBlob"];

                //get the reference to the Blob Container of the secure Desk
                BlobContainerClient container = new BlobContainerClient(connection_String, "mysecuredeskcontainer");

                if (!isForgetPassword)
                {
                    mailMessage.Subject = "OTP for Secure Desk";
                    //mailMessage.Body = "Otp code is : " + otpString;

                    //get the refernence to the BlobClient to retrieve the file from the azure blob
                    BlobClient blobClient = container.GetBlobClient("SecureDeskEmailFormat.html");
                    //download the file
                    var response = await blobClient.DownloadAsync();

                    string htmlBody = "";

                    //read all the content from the file
                    using (var streamReader = new StreamReader(response.Value.Content))
                    {
                        while (!streamReader.EndOfStream)
                        {
                            htmlBody += await streamReader.ReadLineAsync();
                        }
                    }

                    htmlBody = htmlBody.Replace("#userName#", userName);
                    htmlBody = htmlBody.Replace("#otpNumber#", otpString);
                    mailMessage.IsBodyHtml = true;
                    mailMessage.Body       = htmlBody;
                    //Create the smtp Client and send the email to the user
                    SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
                    smtpClient.Credentials = new System.Net.NetworkCredential()
                    {
                        //Get the network credntials from the Azure Configuration
                        UserName = System.Configuration.ConfigurationManager.AppSettings["SecureDeskEmailAddress"],
                        Password = System.Configuration.ConfigurationManager.AppSettings["SecureDeskEmailPassword"]
                    };
                    //Enabling the SSL level of security of the email
                    smtpClient.EnableSsl = true;
                    //send the Email to the user
                    smtpClient.Send(mailMessage);
                }
                else
                {
                    mailMessage.Subject = "Reset Your Password For Secure Desk Account";
                    //mailMessage.Body = "Otp code is : " + otpString;

                    //get the refernence to the BlobClient to retrieve the file from the azure blob
                    BlobClient blobClient = container.GetBlobClient("ForgetPasswordSecureDeskEmail.html");
                    //download the file
                    var response = await blobClient.DownloadAsync();

                    string htmlBody = "";

                    //read all the content from the file
                    using (var streamReader = new StreamReader(response.Value.Content))
                    {
                        while (!streamReader.EndOfStream)
                        {
                            htmlBody += await streamReader.ReadLineAsync();
                        }
                    }

                    htmlBody = htmlBody.Replace("#userName#", userName);
                    htmlBody = htmlBody.Replace("#otpNumber#", otpString);
                    mailMessage.IsBodyHtml = true;
                    mailMessage.Body       = htmlBody;
                    //Create the smtp Client and send the email to the user
                    SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
                    smtpClient.Credentials = new System.Net.NetworkCredential()
                    {
                        //Get the network credntials from the Azure Configuration
                        UserName = System.Configuration.ConfigurationManager.AppSettings["SecureDeskEmailAddress"],
                        Password = System.Configuration.ConfigurationManager.AppSettings["SecureDeskEmailPassword"]
                    };
                    //Enabling the SSL level of security of the email
                    smtpClient.EnableSsl = true;
                    //send the Email to the user
                    smtpClient.Send(mailMessage);
                }

                return(true);
            }
            catch (Exception ex)
            {
                //catch and throw the exception
                throw new Exception(ex.Message);
            }
        }