// Generate OTP public void GenerateOTP(string transactionID) { try { OTP otpEntity = new OTP(); Random r = new Random(); var OTPNumber = r.Next(1000000, 99999999); var transactionExists = _changerMintsUOW.Repository <OTP>().Query().Filter(q => q.TransactionID == transactionID).Get().FirstOrDefault(); otpEntity.ValidFrom = DateTime.Now; otpEntity.ValidTo = DateTime.Now.AddMinutes(3); if (transactionExists != null) { transactionExists.OTPNumber = OTPNumber; transactionExists.Hits++; } else { otpEntity.OTPNumber = OTPNumber; otpEntity.IsActive = true; otpEntity.Hits = 0; _changerMintsUOW.Repository <OTP>().Insert(otpEntity); } _changerMintsUOW.Save(); } catch (Exception e) { throw e; } }
public bool IsOTPChk(string OTPCHK, string OtpEmail) { bool IsOTPChk = false; try { var result = db.OTP.Select(x => new { otpid = x.otpid, otpcode = x.OTPCode, otpEmail = x.OTPEmail, otpMobile = x.OTPMobile, otpIsActive = x.IsActive }).Where(s => s.otpcode == OTPCHK).ToList(); for (int i = 0; i < result.Count(); i++) { if (result[i].otpcode == OTPCHK && result[i].otpEmail == OtpEmail && result[i].otpMobile == OtpEmail) { if (result[i].otpIsActive == true) { OTP f = db.OTP.Find(Convert.ToInt32(result[i].otpid)); f.IsActive = false; db.SaveChanges(); IsOTPChk = true; } } } //if(result) } catch (Exception ex) { } return(IsOTPChk); }
private async Task <int> GetOtp(string email) { var user = db.UserTables.Where(w => w.Email == email).FirstOrDefault(); var otpData = db.OTPs.Where(w => w.UserID == user.UserID).FirstOrDefault(); if (otpData != null) { db.OTPs.Remove(otpData); db.SaveChanges(); } Random generator = new Random(); int r = generator.Next(100000, 1000000); OTP otp = new OTP(); otp.UserID = user.UserID; otp.OTP1 = r; db.OTPs.Add(otp); db.SaveChanges(); SmtpClient smtp = new SmtpClient(); MailMessage mailMessage = new MailMessage(); mailMessage.From = new MailAddress("*****@*****.**"); mailMessage.To.Add(email); mailMessage.Subject = "Forgot Password"; mailMessage.Body = "Dear Customer...Your OTP is " + r; await Task.Run(() => smtp.SendAsync(mailMessage, null)); return(r); }
public async Task <IActionResult> RequestForNewAccessCode([FromQuery] AccessCode accessCode) { if (string.IsNullOrEmpty(accessCode.EmailOrMobile)) { return(new BadRequestObjectResult("EmailOrMobile must be needed")); } User resultForUser = await GetUserDetailByEmailOrMobile(accessCode.EmailOrMobile, accessCode.IsMobileNumber); if (resultForUser == null) { return(new BadRequestObjectResult("User not exits")); } if (resultForUser.Id == Guid.Empty) { return(new BadRequestObjectResult("User not exits")); } OTP objOTP = await InsertNewOTP(resultForUser.Id, "RA"); if (objOTP.Id == Guid.Empty && string.IsNullOrEmpty(objOTP.Code)) { return(new NotFoundObjectResult("OTP not insert successfully")); } return(new OkObjectResult(objOTP.Code)); }
public static long Insert(OTP otp) { using (var db = DatabaseService.Connection) { Dapper.SqlMapper.SetTypeMap(typeof(OTP), new ColumnAttributeTypeMapper <OTP>()); return(db.Query <long>(ScriptService.Scripts["otp_insert"], otp).Single()); } }
public static void UpdateActive(OTP otp) { using (var db = DatabaseService.Connection) { Dapper.SqlMapper.SetTypeMap(typeof(OTP), new ColumnAttributeTypeMapper <OTP>()); db.Execute(ScriptService.Scripts["otp_update_active"], otp); } }
public IHttpActionResult PostOTP([FromBody] OTP value) { try { var context = new xPenEntities(); string Message = "Register with IES Master using OTP " + value.String_OTP; var user = (from u in context.IESUserProfiles where u.MobileNumber == value.MobileNumber select u).ToList(); if (user.Count == 1) { String result = Utility.sendSMS(Message, value.MobileNumber); JObject json = JObject.Parse(result); String status = json.GetValue("status").ToString(); return(Ok(json)); } else if (user.Count == 0) { CustomResponse cr = new CustomResponse(); cr.Response = "Mobile number is not registered"; return(BadRequest()); } else { return(BadRequest()); } } catch (Exception Ex) { return(InternalServerError()); } }
public async Task <IActionResult> Registration([FromBody] Registation registation) { try { if (string.IsNullOrEmpty(registation.Mobile) || string.IsNullOrEmpty(registation.Email) || string.IsNullOrEmpty(registation.Password)) { return(new BadRequestObjectResult("Request not proper")); } var resultByMobileNumber = await _userProvider.GetByMobileNumberAsync(registation.Mobile); if (resultByMobileNumber != null) { if (resultByMobileNumber.Id != Guid.Empty) { return(new BadRequestObjectResult("Mobile number already exits")); } } var resultByEmail = await _userProvider.GetByEmailAsync(registation.Email); if (resultByEmail != null) { if (resultByEmail.Id != Guid.Empty) { return(new BadRequestObjectResult("Email already exits")); } } User user = new User(); user.MobileNumber = registation.Mobile; user.Email = registation.Email; user.Password = registation.Password; user.CreatedOn = DateTime.Now.ToUniversalTime(); user.UpdatedOn = DateTime.Now.ToUniversalTime(); user.CreatedBy = DefultValueHelper.DEFAULT_SYSTEMUSER; user.UpdatedBy = DefultValueHelper.DEFAULT_SYSTEMUSER; user.IsActive = false; await _userProvider.AddAsync(user); Guid userid = user.Id; if (userid != Guid.Empty) { OTP objOTP = await InsertNewOTP(userid, "STS"); if (objOTP.Id != Guid.Empty && !string.IsNullOrEmpty(user.Email)) { await _IEmailHelper.SendEmail(new EmailData { FromEmails = DefultValueHelper.DEFAULT_FROM_EMAIL, ToEmails = user.Email, Subject = "Access code for portal", Body = objOTP.Code }); } } return(new OkResult()); } catch (Exception ex) { throw ex; } }
private void oTPToolStripMenuItem_Click(object sender, EventArgs e) { OTP f = new OTP(); DisposeAllButThis(f); f.MdiParent = this; f.Show(); }
public bool OTPEmail(string Email, string EmailBody, string Subject) { bool IsEmailSend = false; int lastCustId = 0; if (CheckCustomeexist(Email)) { lastCustId = 0000; } else { try { using (MailMessage mail = new MailMessage()) { mail.From = new MailAddress("*****@*****.**");//[email protected] mail.To.Add(Email); mail.Subject = Subject; int _min = 1000; int _max = 9999; Random _rdm = new Random(); int rnum = _rdm.Next(_min, _max); mail.Body = EmailBody + rnum; mail.IsBodyHtml = true; // mail.Attachments.Add(new Attachment("C:\\file.zip")); using (SmtpClient smtp = new SmtpClient())//465 //587 { smtp.EnableSsl = true; smtp.UseDefaultCredentials = false; //smtp.Credentials = new NetworkCredential("*****@*****.**", "nayananm291193"); smtp.Credentials = new NetworkCredential("*****@*****.**", "KauBagwe21"); smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.Send(mail); IsEmailSend = true; OTP otpcode = new OTP(); otpcode.OTPCode = rnum.ToString(); otpcode.OTPEmail = Email; otpcode.OTPMobile = Email; otpcode.IsActive = true; otpcode.IsDelete = false; otpcode.IsUpdate = false; otpcode.InsertDate = DateTime.Now; otpcode.LMDDate = DateTime.Now; db.OTP.Add(otpcode); db.SaveChanges(); } } } catch (Exception ex) { } } return(IsEmailSend); }
/// <summary> /// Returns true if OutputCredentialsInfo instances are equal /// </summary> /// <param name="other">Instance of OutputCredentialsInfo to be compared</param> /// <returns>Boolean</returns> public bool Equals(OutputCredentialsInfo other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( Description == other.Description || Description != null && Description.Equals(other.Description) ) && ( Key == other.Key || Key != null && Key.Equals(other.Key) ) && ( Cert == other.Cert || Cert != null && Cert.Equals(other.Cert) ) && ( AuthMode == other.AuthMode || AuthMode != null && AuthMode.Equals(other.AuthMode) ) && ( SCAL == other.SCAL || SCAL != null && SCAL.Equals(other.SCAL) ) && ( PIN == other.PIN || PIN != null && PIN.Equals(other.PIN) ) && ( OTP == other.OTP || OTP != null && OTP.Equals(other.OTP) ) && ( Multisign == other.Multisign || Multisign != null && Multisign.Equals(other.Multisign) ) && ( Lang == other.Lang || Lang != null && Lang.Equals(other.Lang) )); }
public async Task <object> GetBy(OTP parameters) { Random random = new Random(); int randomNumber = random.Next(1000, 9999); return(await Task.FromResult(randomNumber)); //throw new NotImplementedException(); }
public bool ValidateOTP(OTP otp) { string sql = @"Udemi_User_ValidateOTP"; var dt = ExecuteDataTable(sql, CommandType.StoredProcedure, new SqlParameter("@OTP", otp.Value)); if (!dt.Rows[0]["err_code"].ToString().Equals("0")) { return(false); } return(true); }
/** * Generates an OTP with an attached user for callback. * Also stores the object in the database. * * @param - the user for which the OTP applies * @returns - the OTP generated and stored in the databse */ public static OTP GenerateOtp(User u) { var otp = new OTP { Time = DateTime.Now, UserId = u.UserId, Code = RandomString(64) }; otp.Id = DatabaseOtpService.Insert(otp); return(otp); }
public ActionResult EnterOtp(OTP o1) { if (Session["OTP"].ToString().Equals(o1.Otp.ToString())) { return(RedirectToAction("ChangePass")); } else { return(Content("<script language='javascript' type='text/javascript'>alert('Please Enter Corract OTP !!!'); window.location.replace('EnterOtp');</script>")); } }
public async Task DeleteAsync(OTP parameters) { var currenttime = System.DateTime.Now; if (parameters.DeactivateTime < currenttime) { var deactivateotp = Uow.Repository <OTP>().FindByKey(parameters.OTPId); await Uow.RegisterDeletedAsync(deactivateotp); await Uow.CommitAsync(); } }
public async Task <object> GetBy(OTP parameters) { Random rand = new Random(); parameters.OtpNumber = rand.Next(1000, 9999); parameters.ActivateTime = System.DateTime.Now; parameters.DeactivateTime = parameters.ActivateTime.AddMinutes(2); await Uow.RegisterNewAsync(parameters); await Uow.CommitAsync(); return(await Task.FromResult(parameters.OTPId)); }
public async Task <bool> UpdateAsync(Guid id, OTP otp) { try { ReplaceOneResult replaceOneResult = await _context.OTPs.ReplaceOneAsync(n => n.Id.Equals(id), otp, new UpdateOptions { IsUpsert = true }); return(replaceOneResult.IsAcknowledged && replaceOneResult.ModifiedCount > 0); } catch (Exception ex) { throw ex; } }
public async Task AddAsync(OTP otp) { try { otp.CreatedOn = DateTime.Now.ToUniversalTime(); otp.UpdatedOn = DateTime.Now.ToUniversalTime(); await _context.OTPs.InsertOneAsync(otp); } catch (Exception ex) { throw ex; } }
public IHttpActionResult VerifyOTP(OTP oTP) { return(GetJsonResult(new BaseResponse() { Message = "OTP validation request.", ResponseObject = new MiddelLayer.OTP().Update(new OTP() { Id = oTP.Id, Code = oTP.Code }), StatusCode = 200 })); }
public async Task <object> GetBy(OTP parameters) { var isOtpIdTrue = await Uow.Repository <OTP>().SingleOrDefaultAsync(t => t.OTPId == parameters.OTPId && t.OTPNumber == parameters.OTPNumber); if (isOtpIdTrue != null) { return(await Task.FromResult("True")); } else { return(await Task.FromResult("False")); } }
public Boolean sendResetPasswordMail(string mail, out string msg, out OTP otp) { var usr = usrRepo.GetUserList(mail).FirstOrDefault(); string subject = ""; EmailTemplate et = new EmailTemplate(); et.Mail_Content = MailContent(usr, out subject, out otp); //et.Mail_bcc.Add("*****@*****.**"); et.Mail_To.Add(mail); et.Mail_Subject = subject; var flag = GenericClass.sendMail(et, out msg); return(flag); }
public async Task <object> GetBy(OTP parameters) { Random random = new Random(); int randomNumber = random.Next(1000, 9999); parameters.OTPNumber = randomNumber; await Uow.RegisterNewAsync(parameters); await Uow.CommitAsync(); return(await Task.FromResult(parameters.OTPId)); //throw new NotImplementedException(); }
public ActionResult Login(string phonenumber) { // just a bit of input cleanup phonenumber = new Regex("[\\(\\)\\s+\\-]").Replace(phonenumber, ""); if (!phonenumber.StartsWith("+")) { if (phonenumber.Length == 10) { phonenumber = "+1" + phonenumber; } else { phonenumber = "+" + phonenumber; } } else { if (phonenumber.Length == 11) { phonenumber = "+1" + phonenumber.Substring(1); } } // TODO Tyler - skip this step and get patient directly from phone number? var user = DatabaseUserService.GetByPhoneActive(phonenumber); if (user == null) { return(Code(null)); } var patient = DatabasePatientService.GetByUserIdActive(user.UserId); if (patient == null) { return(Code(null)); } var otp = new OTP() { UserId = patient.UserId, Time = DateTime.Now, Code = new Random().Next(0, 1000000).ToString("000000") }; DatabaseOtpService.Insert(otp); NotificationSender.SendNotification(patient, "Your one-time patient login code is " + otp.Code); return(Code(patient.UserId)); }
public async Task <object> GetAsync(OTP parameters) { var temp = 0; temp = Uow.Repository <OTP>().Count(t => t.OTPId == parameters.OTPId && t.OtpNumber == parameters.OtpNumber); if (temp != 0) { return(await Task.FromResult("Successfull Verified")); } else { return(await Task.FromResult("Enter correct otp")); } }
/// <summary> /// Returns true if InputCredentialsAuthorize instances are equal /// </summary> /// <param name="other">Instance of InputCredentialsAuthorize to be compared</param> /// <returns>Boolean</returns> public bool Equals(InputCredentialsAuthorize other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( CredentialID == other.CredentialID || CredentialID != null && CredentialID.Equals(other.CredentialID) ) && ( NumSignatures == other.NumSignatures || NumSignatures != null && NumSignatures.Equals(other.NumSignatures) ) && ( Hash == other.Hash || Hash != null && Hash.Equals(other.Hash) ) && ( PIN == other.PIN || PIN != null && PIN.Equals(other.PIN) ) && ( OTP == other.OTP || OTP != null && OTP.Equals(other.OTP) ) && ( Description == other.Description || Description != null && Description.Equals(other.Description) ) && ( ClientData == other.ClientData || ClientData != null && ClientData.Equals(other.ClientData) )); }
public static int ValidateOTP(string phone_number, string otp_pwd) { /* returning value * 0 - pass * 1 - failed, try again * 2 - failed, start over * 3 - expired, start over */ long number = Convert.ToInt64(phone_number); using (var db = new EchoContext()) { OTP otp = db.OTPs.SingleOrDefault(x => x.PhoneNumber.Equals(phone_number)); if (otp == null) { return(2); } if (otp.Counter >= 3) { return(2); } int cmp = DateTime.Compare(DateTime.Now, otp.Expired_Dttm); if (cmp > 0) { return(3); } string check_otp = GenerateOTP(otp.Secret, number); if (check_otp.Equals(otp_pwd)) { return(0); } else { otp.Counter += 1; db.Entry(otp).State = EntityState.Modified; db.SaveChanges(); if (otp.Counter >= 3) { return(2); } return(1); } } }
public bool GenerateAndSendOTP(int userID) { _context = new MIDASGBXEntities(); Repository.User user = _context.Users.Where(u => u.id == userID).FirstOrDefault(); int defaultAdminUserID = Convert.ToInt32(Common.Utility.GetConfigValue("DefaultAdminUserID")); bool result = false; try { if (user != null) { var existingOTP = _context.OTPs.Where(p => p.UserID == userID).ToList(); existingOTP.ForEach(a => { a.IsDeleted = true; a.UpdateDate = DateTime.UtcNow; a.UpdateByUserID = defaultAdminUserID; }); } OTP otp = new OTP(); otp.OTPCode = Common.Utility.GenerateRandomNumber(6); otp.Pin = Common.Utility.GenerateRandomNo(); otp.UserID = user.id; otp.CreateDate = DateTime.UtcNow; otp.CreateByUserID = Convert.ToInt32(defaultAdminUserID); otp.IsDeleted = false; _context.OTPs.Add(otp); _context.SaveChanges(); string Message = "Dear " + user.FirstName + ",<br><br>As per your request, a One Time Password (OTP) has been generated and the same is <i><b>" + otp.OTPCode.ToString() + "</b></i><br><br>Please use this OTP to complete the Login. Reference number is " + otp.Pin.ToString() + " <br><br>*** This is an auto-generated email. Please do not reply to this email.*** <br><br>Thanks" + " <br><br>MIDAS Administrator"; Common.Email mail = new Common.Email(); mail.ToEmail = user.UserName; mail.Subject = "OTP Alert Message From GBX MIDAS"; mail.Body = Message; mail.SendMail(); result = true; } catch { result = false; } return(result); }
private async Task <OTP> InsertNewOTP(Guid userid, string type) { OTP objOTP = new OTP(); objOTP.Code = OTPHelper.GetNewOTP(); objOTP.UserId = userid; objOTP.IsUsed = false; objOTP.Type = type; objOTP.ExpiryDateTime = DefultValueHelper.DEFAULT_OTP_EXPRIRE_TIME; objOTP.CreatedBy = DefultValueHelper.DEFAULT_SYSTEMUSER; objOTP.CreatedOn = DateTime.Now.ToUniversalTime(); objOTP.UpdatedBy = DefultValueHelper.DEFAULT_SYSTEMUSER; objOTP.UpdatedOn = DateTime.Now.ToUniversalTime(); await _OTPProvider.AddAsync(objOTP); return(objOTP); }
public ActionResult VerifyOTP(OTP otpModel) { if (Request.Cookies["OTP"].Value == otpModel.OTPvalue) { Session["uname"] = Session["tuname"]; Session["userID"] = Session["tuserID"]; Session["Phonenumber"] = Session["tPhonenumber"]; Session["username"] = Session["tusername"]; Session["userBeans"] = Session["tuserBeans"]; Session["role"] = Session["trole"]; return(RedirectToAction("Index", "Game")); } else { return(RedirectToAction("SendOTP", "SMS")); } }