public bool Register(RegisterPackage package) { if (null != package.Phone && "" != package.Phone) { string sql_checkphone = "select * from " + DBStaticData.DataBaseUserTableName + " where " + DBStaticData.DataBaseUserTablePhoneField + " = '" + package.Phone + "'"; if (ExecuteNonDataSet(sql_checkphone, out DataSet set)) { if (0 != set.Tables.Count) { if (0 != set.Tables[0].Rows.Count) { return(false); } } else { return(false); } } else { return(false); } } string token = DBStaticMethod.GetToken(); string sql = string.Format ( "insert into {0} values ('{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', {8})", DBStaticData.DataBaseUserTableName, package.ID, DBStaticMethod.SHA256(package.Password, token), token, package.Name, package.Email, package.Phone, package.Describe, package.Photo.ToString() ); if (!ExecuteNonQuery(sql)) { return(false); } return(true); }
public bool UpdatePassword(string email, string npw) { string token = DBStaticMethod.GetToken(); string sql = string.Format ( "update {0} set {1} = '{2}', {3} = '{4}' where {5} = '{6}'", DBStaticData.DataBaseUserTableName, DBStaticData.DataBaseUserTableTokenField, token, DBStaticData.DataBaseUserTablePasswordField, DBStaticMethod.SHA256(npw, token), DBStaticData.DataBaseUserTableEmailField, email ); return(ExecuteNonQuery(sql)); }
public LoginResult Login(string user, string pw, LoginType type, out string userid) { string sql = string.Format ( "select {0}, {1}, {2} from {3} where ", DBStaticData.DataBaseUserTablePasswordField, DBStaticData.DataBaseUserTableTokenField, DBStaticData.DataBaseUserTableIDField, DBStaticData.DataBaseUserTableName ); userid = ""; switch (type) { case LoginType.Email: sql += DBStaticData.DataBaseUserTableEmailField + " = '" + user + "'"; break; case LoginType.Phone: sql += DBStaticData.DataBaseUserTablePhoneField + " = '" + user + "'"; break; case LoginType.Identification: sql += DBStaticData.DataBaseUserTableIDField + " = '" + user + "'"; break; default: return(LoginResult.Error_Server); } if (ExecuteNonDataSet(sql, out DataSet set)) { if ( 0 < set.Tables.Count && 0 < set.Tables[0].Rows.Count ) { string password = set.Tables[0].Rows[0].ItemArray[0] as string; string token = set.Tables[0].Rows[0].ItemArray[1] as string; if (DBStaticMethod.SHA256(pw, token).Equals(password)) { userid = set.Tables[0].Rows[0].ItemArray[2] as string; return(LoginResult.Success); } else { return(LoginResult.Error_Password); } } else { switch (type) { case LoginType.Email: return(LoginResult.Error_Email); case LoginType.Phone: return(LoginResult.Error_Phone); case LoginType.Identification: return(LoginResult.Error_User); } } } return(LoginResult.Error_Server); }