public bool CheckCode(string phone, string code) { account_code account_code = entity.account_code.FirstOrDefault(p => p.phone == phone); TimeSpan timeSpan = DateTime.Now.Subtract(account_code.sys_datetime.Value); if (timeSpan.TotalMinutes <= this.expireTime) { return(account_code.code == code); } return(false); }
public string CreateCode(string phone) { Random random = new Random(); string codeStr = random.Next(1000, 10000).ToString(); account_code account_code = entity.account_code.FirstOrDefault(p => p.phone == phone); if (account_code == null) { account_code new_account_code = new account_code() { code = codeStr, phone = phone, sys_datetime = DateTime.Now, }; entity.account_code.Add(new_account_code); } else { account_code.code = codeStr; account_code.sys_datetime = DateTime.Now; } entity.SaveChanges(); return(codeStr); }