public LoginObj ValidateLogin(String uname, String pwd) { LoginObj lg = new LoginObj(); lg.Name = ""; String q = "SELECT Name,Clearancelevel FROM Login WHERE Username = '******'" + " AND Password = '******'"; SqlCommand cmd = new SqlCommand(q, con); SqlDataReader reader; con.Open(); try { reader = cmd.ExecuteReader(); if (reader.HasRows) { reader.Read(); lg.Name = reader.GetString(0); lg.Clearancelevel1 = reader.GetInt32(1); } else { lg.Name = ""; } } catch (Exception ex) { MessageBox.Show("Error\n\n" + ex); } con.Close(); return(lg); }
//**end** private void loginbtn_Click(object sender, EventArgs e) { if (login_tb_username.Text != "" && login_tb_password.Text != "") { if (login_tb_password.Text.Length == 12) { DBAccess db = new DBAccess(); LoginObj lg = new LoginObj(); lg = db.ValidateLogin(login_tb_username.Text, login_tb_password.Text); if (lg.Name != "") { //MessageBox.Show(name); this.Hide(); Home hm = new Home(lg.Name, lg.Clearancelevel1); hm.ShowDialog(); Close(); } else { MessageBox.Show("Incorrect username or password"); } } else { MessageBox.Show("Password must have 12 characters"); } } else { MessageBox.Show("Username / Password missing."); } }
public ActionResult Login(LoginObj login) { if (!string.IsNullOrEmpty(login.username) && !string.IsNullOrEmpty(login.password)) { FormsAuthentication.SetAuthCookie(login.username, false); return(Redirect(FormsAuthentication.GetRedirectUrl(login.username, false))); } return(View(login)); }
private bool AuthenticateApiCaller(string ApiKey, LoginObj obj, out DataSet ds, out int ReturnVal, out string ReturnMsg) { AuthenticationDAO objAuthDAO = new AuthenticationDAO(_ConStr); ds = objAuthDAO.FetchValidateUser(ApiKey, obj, out ReturnVal, out ReturnMsg); if (ReturnVal == 1) { return(true); } else { return(false); } }
// Use this for initialization void Start() { for (int i = 0; i < 5; ++i) { for (int j = 0; j < 5; ++j) { GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Sphere); obj.transform.localScale = scale_; obj.transform.position = new Vector3(i * 20 - dev_, 0, j * 20 - dev_); LoginObj loginObj = obj.AddComponent <LoginObj>(); loginObj.Init("name_" + i + "_" + j, "passwd_" + i + "_" + j); TestManager.Instance.lsLoginObj_.Add(loginObj); } } }
public ActionResult Login() { dynamic PostDataArrived = CS.GetPostData(this.Request); try { LoginObj loginObj = new LoginObj(); loginObj.Email = (string)PostDataArrived.Email; loginObj.Password = (string)PostDataArrived.Password; SingleSignONService ssoService = new SingleSignONService(); return(CS.ReturnForJQuery(ssoService.Login(loginObj))); } catch (Exception) { return(CS.ReturnForJQuery(ControllerSupport.ErrorOccured)); } }
public object Post([FromBody] LoginObj loginObj) { if (loginObj.UserName == "John" && loginObj.Password == "password") { TokenManager tokenManager = new TokenManager(); string token = tokenManager.CreateToken(new User() { Name = loginObj.UserName, Privilege = "user" }); return(new { jwtToken = token, message = "Authentication successful." }); } else { return(new { message = "Authentication failed." }); } }
public DataSet FetchValidateUser(string apikey, LoginObj obj, out int ReturnVal, out string ReturnMsg) { DataSet ds = null; try { List <DBParameter> pList = new List <DBParameter>(); pList.Add(new DBParameter("web_app_url", SqlDbType.VarChar, 500, ParameterDirection.Input, obj.Host)); pList.Add(new DBParameter("login_id", SqlDbType.VarChar, 255, ParameterDirection.Input, obj.UserName)); pList.Add(new DBParameter("access_code", SqlDbType.VarChar, 50000, ParameterDirection.Input, obj.Password)); pList.Add(new DBParameter("ReturnVal", SqlDbType.Int, 0, ParameterDirection.Output, 0)); pList.Add(new DBParameter("ReturnMsg", SqlDbType.VarChar, 50000, ParameterDirection.Output, "")); objDAO = new DAO(_constr); ds = objDAO.GetDataSet("dbo.Get_Validate_USER", DAO.QueryType.StoredProcedure, pList, out ReturnVal, out ReturnMsg); return(ds); } catch (Exception) { throw; } }
/// <summary> /// 跳转到培训 /// </summary> public void GoToTrainee(HttpContext context) { DataTable dt = dataitemdetailbll.GetListByCode("SafetyTrainee"); //获取对应的安全培训配置项 Operator users = OperatorProvider.Provider.Current(); //当前用户 UserEntity person = userbll.GetEntity(users.UserId); SingleUser entity = new SingleUser(); entity.account = users.Account; entity.password = HttpCommon.MD5Encrypt(users.Password); entity.name = users.UserName; entity.mobileNo = person.Telephone; entity.sex = person.Gender == "男" ? "1" : "0"; entity.idType = "0"; entity.idNumber = person.IdentifyID; entity.email = person.Email; entity.isValid = "1"; string openId = person.OpenId; // openid(单点登陆唯一标识) DataRow[] rows = dt.Select(string.Format(" itemname = '{0}'", users.OrganizeId)); //当前培训信息 string traineerInfo = string.Empty; if (rows.Count() > 0) { traineerInfo = rows[0]["itemvalue"].ToString(); } if (!string.IsNullOrEmpty(traineerInfo)) { #region 具体操作内容 string[] arrTrainee = traineerInfo.Split('|'); string version = arrTrainee[0].ToString(); //版本 string appCode = arrTrainee[1].ToString(); //应用代码 skc string secretKey = arrTrainee[2].ToString(); //应用密钥//4DAA67B83F932CBD CB93FE6E34B90127 string account = person.Telephone; string singleValue = string.Empty; string yqStr = string.Empty; string rqUrl = string.Empty; string result = string.Empty; ////用户中心密码 string returnPwd = HttpCommon.MD5Encrypt(users.Password); ////当前用户手机号不能为空 if (string.IsNullOrEmpty(account)) { //跳转到错误页面 context.Response.Redirect("~/Error/ErrorMessage", false); } try { ////第一步,进行验签 GetAccountObj aobj = new GetAccountObj(); aobj.account = person.Telephone; aobj.appCode = appCode; aobj.secretKey = secretKey; aobj.version = version; yqStr = JsonConvert.SerializeObject(aobj); singleValue = HttpCommon.MD5EncryptFor32(yqStr); //验证是否存在当前用户 string validateStr = dt.Select(" itemname = 'TraineeValidate'")[0]["itemvalue"].ToString(); rqUrl = string.Format(validateStr, version, appCode, person.Telephone, singleValue); result = HttpCommon.HttpPost(rqUrl); dynamic dy = JsonConvert.DeserializeObject <ExpandoObject>(result); string code = dy.code; //账号不存在 if (code == "B000009") { string userJson = JsonConvert.SerializeObject(entity); string aesData = HttpCommon.AesEncrypt(userJson, secretKey); RegisterObj yqObj = new RegisterObj(); yqObj.appCode = appCode; yqObj.data = aesData; yqObj.secretKey = secretKey; yqObj.version = version; yqStr = JsonConvert.SerializeObject(yqObj); singleValue = HttpCommon.MD5EncryptFor32(yqStr); //注册信息 string registerStr = dt.Select(" itemname = 'TraineeRegister'")[0]["itemvalue"].ToString(); rqUrl = string.Format(registerStr, version, appCode, aesData, singleValue); if (rqUrl.Contains("+")) { rqUrl = rqUrl.Replace("+", "%2B"); } result = HttpCommon.HttpPost(rqUrl); } else { //成功状态 if (code == "000000") { //获取账号后 string data = dy.data.ToString(); if (!string.IsNullOrEmpty(data)) { data = data.Replace("\r\n", ""); } string userStr = HttpCommon.AesDecrypt(data, secretKey); dynamic userdy = JsonConvert.DeserializeObject <ExpandoObject>(userStr); openId = userdy.openId; returnPwd = userdy.password.ToString(); //如果当前账号下本地数据库中openid为空 if (string.IsNullOrEmpty(person.OpenId)) { //更新人员信息表,将openId 存入person信息表当中 //person.OpenId = openId; //userbll.SaveForm(person.UserId, person); //更新人员信息表,将openId 存入person信息表当中 string usql = string.Format("update base_user set openid = '{0}' where userid = '{1}'", openId, person.UserId); //待更新 int excuteResult = userbll.ExcuteBySql(usql); } } } //登录用户中心获取票据 LoginObj loginobj = new LoginObj(); loginobj.account = person.Telephone; loginobj.appCode = appCode; loginobj.password = returnPwd; loginobj.secretKey = secretKey; loginobj.version = version; yqStr = JsonConvert.SerializeObject(loginobj); singleValue = HttpCommon.MD5EncryptFor32(yqStr); //跳转到注册页面 string loginStr = dt.Select(" itemname = 'TraineeLogin'")[0]["itemvalue"].ToString(); rqUrl = string.Format(loginStr, version, appCode, loginobj.account, loginobj.password, singleValue); if (rqUrl.Contains("+")) { rqUrl = rqUrl.Replace("+", "%2B"); } result = HttpCommon.HttpPost(rqUrl); dynamic logindy = JsonConvert.DeserializeObject <ExpandoObject>(result); if (logindy.code.ToString() == "000000") { string logindata = logindy.data.ToString(); if (!string.IsNullOrEmpty(logindata)) { logindata = logindata.Replace("\r\n", ""); } string loginstr = HttpCommon.AesDecrypt(logindata, secretKey); dynamic lastdy = JsonConvert.DeserializeObject <ExpandoObject>(loginstr); string ticket = lastdy.ticket; //票据 string traineeStr = dt.Select(" itemname = 'TraineeUrl'")[0]["itemvalue"].ToString(); string sendurl = string.Format(traineeStr, ticket); context.Response.Redirect(sendurl, false); } else { context.Response.Redirect("~/Error/ErrorMessage", false); } } catch (Exception ex) { context.Response.Redirect("~/Error/ErrorMessage", false); } #endregion } }
public LoginViewModel(INavigationService navigationService) : base(navigationService) { _loginObj = new LoginObj(); SignInCommand = new DelegateCommand(SignInAsync); }
public IActionResult AuthorizationToken([FromRoute] string ApiKey, [FromBody] LoginObj obj) { IActionResult response = Unauthorized(); UserAuthenticationResponse resp = new UserAuthenticationResponse(); try { DataSet ds; int ReturnVal; string ReturnMsg; var IsAuth = AuthenticateApiCaller(ApiKey, obj, out ds, out ReturnVal, out ReturnMsg); if (IsAuth) { var tokenString = ""; if (String.IsNullOrEmpty(ds.Tables[0].Rows[0]["active_api_token"].ToString())) { UserJwt uj = GenerateJSONWebToken(); tokenString = uj.token_String; int ReturnVal_utj; string ReturnMsg_utj; UserApiTokenObj utj = new UserApiTokenObj(); utj.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString()); utj.api_token = uj.token_String; utj.token_expiry = uj.expiry; SetUserApiToken(ApiKey, utj, out ReturnVal_utj, out ReturnMsg_utj); if (ReturnVal_utj != 1) { resp.statuscode = (int)Common.ResponseStatusCode.SqlException; resp.message = ReturnMsg_utj; response = Conflict(resp); return(response); } } else { tokenString = ds.Tables[0].Rows[0]["active_api_token"].ToString(); } resp.statuscode = (int)Common.ResponseStatusCode.Success; resp.message = "success"; resp.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString()); resp.studio_id = int.Parse(ds.Tables[0].Rows[0]["studio_id"].ToString()); resp.full_name = ds.Tables[0].Rows[0]["full_name"].ToString(); resp.api_key = ds.Tables[0].Rows[0]["api_key"].ToString(); resp.api_token = tokenString; response = Ok(resp); } else { resp.statuscode = (int)Common.ResponseStatusCode.ValidationException; resp.message = ReturnMsg; response = Unauthorized(resp); } } catch (Exception ex) { Common c = new Common(); ExceptionObj exobj = c.GetExceptionObjBase(ex); exobj.form_name = "AuthentcationController"; exobj.page_url = "api/Authentication/AuthorizationToken"; int ReturnVal; string ReturnMsg; ExceptionDAO exd = new ExceptionDAO(_ConStr); exd.SetExceptionLog(ApiKey, exobj, out ReturnVal, out ReturnMsg); resp.statuscode = (int)Common.ResponseStatusCode.Exception; resp.message = ex.Message.ToString(); response = BadRequest(resp); } return(response); }
public IEnumerator Login(string username, string password, LoginCallback callback) { WWW cases = new WWW(baseUrl + "/erp/login-api-json"); yield return(cases); string json = cases.text; /* * foreach(string header_name in cases.responseHeaders.Keys) * { * Debug.Log("GET HEADER[" + header_name + "] = " + cases.responseHeaders[header_name]); * }*/ Debug.Log(json); Dictionary <string, string> result = JsonConvert.DeserializeObject <Dictionary <string, string> >(json); _csrf = result["_csrf.token"]; Debug.Log("_csrf: " + _csrf); LoginObj loginObj = new LoginObj(); loginObj.username = username; loginObj.password = password; json = JsonConvert.SerializeObject(loginObj); Debug.Log("send: " + json); Dictionary <string, string> headers = new Dictionary <string, string>(); headers.Add("Content-Type", "application/json"); headers.Add("_csrf", _csrf); headers.Add("Cookie", "XSRF-TOKEN=" + _csrf); headers.Add("X-XSRF-TOKEN", _csrf); byte[] postData = System.Text.Encoding.UTF8.GetBytes(json); //Now we call a new WWW request WWW www = new WWW(baseUrl + "/erp/login-api-json", postData, headers); yield return(www); string set_cookie = null; foreach (string header_name in www.responseHeaders.Keys) { //Debug.Log("POST HEADER[" + header_name + "] = " + www.responseHeaders[header_name]); if (header_name.ToLower() == "set-cookie") { set_cookie = www.responseHeaders[header_name]; break; } } Debug.Log("POST Set-Cookie: " + set_cookie); if (set_cookie != null) { string[] parts = set_cookie.Split(';'); foreach (string part in parts) { string[] pair = part.Trim().Split('='); if (pair.Length == 2) { string name = pair[0].Trim(); if (name == "JSESSIONID") { sessionId = pair[1].Trim(); } } } } Debug.Log("JSESSIONID: " + sessionId); json = www.text; SpringIdentity si = JsonConvert.DeserializeObject <SpringIdentity>(json); callback(si); }