private void cmdEncode_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(txtString.Text.Trim())) { string CryptKey = txtKey.Text.Trim(); string CryptString = txtString.Text.Trim(); using (Simple3Des wrapper = new Simple3Des(CryptKey)) { txtResult.Text = wrapper.EncryptData(CryptString); } } else if (!string.IsNullOrEmpty(txtResult.Text.Trim())) { using (Simple3Des wrapper = new Simple3Des(txtKey.Text.Trim())) { txtString.Text = wrapper.DecryptData(txtResult.Text.Trim()); } } }
private void button3_Click(object sender, EventArgs e) { System.Management.ManagementClass mc = new ManagementClass("win32_processor"); ManagementObjectCollection moc = mc.GetInstances(); this.textBox1.Text = ""; string cpuId = ""; //this.textBox2.Text = ""; foreach (ManagementObject mo in moc) { //MessageBox.Show(mo["processorid"].ToString()); cpuId = cpuId + mo["processorid"].ToString(); } Simple3Des jm = new Simple3Des(this.textBox2.Text); this.textBox1.Text = jm.EncryptData(cpuId); this.textBox3.Text = cpuId; }
private void LoginForm_Load(object sender, EventArgs e) { //Program.connectstring = "Hello Deny..."; Mydataconn mc = Mydataconn.Load(); if (null != mc) { Simple3Des jm = new Simple3Des("deny01.12345678901234567890zb"); this.textBoxSQLSERVER.Text = mc.Sqlser; this.textDatabaseName.Text = mc.Databs; this.textBoxSQLuser.Text = mc.SqlserUser; this.textBoxSQLPW.Text = jm.DecryptData(mc.ServerKey); this.textBoxuserID.Text = mc.UserID; //this.textBoxuserID.Select(0, 0); this.textBoxuserPW.Focus(); //this.textBoxuserPW.Text = jm.DecryptData(mc.Passwd); } }
private static void OtherMaps(bool quiet, Args CommandLine) { Simple3Des dec = new Simple3Des("A$hbySchool1"); if (CommandLine["m"] != null) { //String username = System.DirectoryServices.AccountManagement.UserPrincipal.Current.UserPrincipalName; String username = Environment.UserName; //+ "@ashbyschool.org.uk"; String password = dec.DecryptData(CommandLine["p"]); //if (username != null) { if (CommandLine["d"] != null) username = username.Split('@')[0] + "@" + CommandLine["d"]; } String line = CommandLine["m"]; String[] parts = line.Split(','); String[] baseparts = parts[0].Split('~'); Uri tempuri = new Uri(baseparts[1]); if (CommandLine["u"] != null) { RunAsync(tempuri, username, password, false, false, false).Wait(); } CookieCollection cookies = SpoAuthUtility.Current.cookieContainer.GetCookies(tempuri); String baseUrl = tempuri.Scheme + "://" + tempuri.Host; InternetSetCookie(baseUrl, null, cookies["FedAuth"].ToString() + "; Expires = " + cookies["FedAuth"].Expires.AddMinutes(0).ToString("R")); InternetSetCookie(baseUrl, null, cookies["rtFA"].ToString() + "; Expires = " + cookies["rtFA"].Expires.AddMinutes(0).ToString("R")); foreach (String part in parts) { String[] drivepaths = part.Split('~'); String drive = drivepaths[0] + ":"; String path = drivepaths[1]; Uri sharepointUri = new Uri(path); DoMap(quiet, sharepointUri, drive, ""); } } }
private void SetConfig() { Simple3Des jm = new Simple3Des("deny01.12345678901234567890zb"); Mydataconn mc = Mydataconn.Load(); if (null == mc) { mc = new Mydataconn(); } mc.Sqlser = this.textBoxSQLSERVER.Text; mc.Databs = this.textDatabaseName.Text; mc.SqlserUser = this.textBoxSQLuser.Text; mc.ServerKey = jm.EncryptData(this.textBoxSQLPW.Text); mc.UserID = DataHelper.ToDBC(this.textBoxuserID.Text); mc.Passwd = jm.EncryptData(this.textBoxuserPW.Text); mc.Save(); }
private void button1_Click(object sender, EventArgs e) { Simple3Des jm = new Simple3Des("deny01.12345678901234567890zb"); System.Management.ManagementClass mcpu = new ManagementClass("win32_processor"); ManagementObjectCollection moc = mcpu.GetInstances(); string scpuCode = ""; foreach (ManagementObject mo in moc) { //MessageBox.Show(mo["processorid"].ToString()); scpuCode = scpuCode + mo["processorid"].ToString(); } if (jm.EncryptData(scpuCode) == this.textBox1.Text) { Mydataconn mc = Mydataconn.Load(); if (null == mc) { mc = new Mydataconn(); } mc.RegisterCode = this.textBox1.Text; mc.Save(); this.DialogResult = DialogResult.OK; } else { MessageBox.Show("注册码错误,请重新输入..."); } }
//[Produces("application/json")] public async Task <string> Post(/*[FromForm] dynamic value, */ [FromRoute] string subRoute, List <IFormFile> files = null) { string[] checker; Users tUser;// Users[] lUser; switch (subRoute.ToLower()) { case "auth": { checker = new string[] { UID, PWD }; if (!CheckPayLoad(checker)) { return(ErrorInvalid()); } if (!ModelState.IsValid) { return(ErrorBadReq()); } tUser = await db.users.SingleOrDefaultAsync(user => user.Username == Request.Form[UID][0]); if (tUser == null) { return(ErrorUserNotFound()); } Simple3Des des = new Simple3Des(Request.Form[UID][0]); if (tUser.Password == des.EncryptData(Request.Form[PWD][0])) { if (tUser.Status == false) { return(Send(new { status = "error", desc = "Your account have been suspended. Due to some reason you are not eligible to use this account.<br>" + "For more information, please ask your administrator." })); } SetAuth(tUser.ID); Console.WriteLine(tUser.Username + "[" + tUser.ID + "] Logged in"); logger.Write(LOG_MODE.ACTION, "ID " + GetID() + " login"); return(Send(new { status = "success" })); } else { return(ErrorWrongPwd()); //Send(new { aa = des.EncryptData(Request.Form[PWD][0]), bb = tUser.UserPassword, cc = tUser.UserId }); } } case "datalist": { checker = new string[] { DT_SKIP, DT_TAKE, DT_REQTOTAL }; if (!CheckAccess(ACCESS.MASTER)) { return(ErrorAccess()); } if (!ModelState.IsValid) { return(ErrorBadReq()); } if (!CheckPayLoad(checker)) { if (!CheckPayLoad(new string[] { DT_REQTOTAL, "sort" })) { return(ErrorInvalid()); } return(false.ToString()); } string sortBy = "ID", search = ""; bool bDesc = false; //var q = db.users.FromSqlRaw("select * from Users"); //var g = db.groups.AsEnumerable(); var query = db.users.Join(db.groups.AsEnumerable(), user => user.ID_Group, group => group.ID, (user, group) => new { ID = user.ID, Username = user.Username, Role = group.Name, Email = user.Email, Status = user.Status, IdGroup = user.ID_Group, CustomAccess = user.Access } ).AsEnumerable(); /*var query = db.users.Select(user => new { * user.ID, user.Username, user.Role, * user.Email, user.Status, IdGroup = user.ID_Group, * CustomAccess = user.Access * }).AsEnumerable();*/ //Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(query.ToList())); if (CheckPayLoad(new string[] { "filter" })) { var filter = JsonConvert.DeserializeObject <JArray>(Request.Form["filter"]); if ((string)filter[0][0] == "Username" && (string)filter[0][1] == "contains") { search = filter[0][2].ToString().ToLower(); query = query.Where(user => //EF.Functions.Like(user.Role, "%" + search + "%") || user.Role.ToLower().Contains(search) || user.Email.ToLower().Contains(search) || user.Username.ToLower().Contains(search) ); } else if ((string)filter[0][0] == "ID" && (string)filter[0][1] == "=") { search = filter[0][2].ToString().ToLower(); query = query.Where(user => user.ID.ToString().Contains(search) || //EF.Functions.Like(user.Role, "%" + search + "%") || user.Role.ToLower().Contains(search) || user.Email.ToLower().Contains(search) || user.Username.ToLower().Contains(search) ); } } if (CheckPayLoad(new string[] { "sort" })) { var sort = JsonConvert.DeserializeObject <JArray>(Request.Form["sort"]); sortBy = (string)sort[0]["selector"]; bDesc = (bool)sort[0]["desc"]; if (bDesc == false) { switch (sortBy.ToLower()) { case "id": query = query.OrderBy(ob => ob.ID); break; case "username": query = query.OrderBy(ob => ob.Username); break; case "role": query = query.OrderBy(ob => ob.Role); break; case "email": query = query.OrderBy(ob => ob.Email); break; case "status": query = query.OrderBy(ob => ob.Status); break; } //query.OrderBy(ob => EF.Property<object>(ob, sortBy)); } else { switch (sortBy.ToLower()) { case "id": query = query.OrderByDescending(ob => ob.ID); break; case "username": query = query.OrderByDescending(ob => ob.Username); break; case "role": query = query.OrderByDescending(ob => ob.Role); break; case "email": query = query.OrderByDescending(ob => ob.Email); break; case "status": query = query.OrderByDescending(ob => ob.Status); break; } } } query = query.Skip(Convert.ToInt32(Request.Form[DT_SKIP][0])); query = query.Take(Convert.ToInt32(Request.Form[DT_TAKE][0])); var data = query.ToList(); if (data.Count() < 1) { return("[]"); } int totalCount = await db.users.CountAsync(); var result = new { data, totalCount = totalCount }; return(Send(result)); } case "new": { try { checker = new string[] { "uid", "pwdNew", "email" /*, "status", "role"*/, "customAccess" }; if (!CheckPayLoad(checker)) { return(ErrorInvalid()); } if (!CheckAccess(ACCESS.USER_ADD)) { return(ErrorAccess()); } if (!ModelState.IsValid) { return(ErrorBadReq()); } var checkUser = await db.users.SingleOrDefaultAsync(user => user.Username == (string)Request.Form["uid"]); if (checkUser != null) { return(ErrorUserExist()); } Simple3Des des = new Simple3Des(Request.Form["uid"]); //Console.WriteLine(Send(Request.Form)); var result = await db.users.AddAsync(new Users { Username = (string)Request.Form["uid"], ID_Group = Request.Form["role"] == "null" || Request.Form["role"] == "undefined" ? 0: Convert.ToInt32(Request.Form["role"]), Status = Convert.ToBoolean(Request.Form["status"]), Email = (string)Request.Form["email"], Access = (string)Request.Form["customAccess"], Password = des.EncryptData((string)Request.Form["pwdNew"]), Logged_In = false }); if (result.State == EntityState.Added) { result.Context.SaveChanges(); } else if (result.State == EntityState.Unchanged) { return(Send(new { status = "error", desc = "Can't add new User, due to the state is remainly unchanged" })); } if (files.Count == 1) { var fStream = new FileStream(hosting.WebRootPath + "\\images\\profiles\\" + result.Entity.ID + ".jpg", FileMode.Create); await files[0].CopyToAsync(fStream); fStream.Dispose(); fStream = null; } else { if (System.IO.File.Exists(hosting.WebRootPath + "\\images\\profiles\\" + result.Entity.ID + ".jpg")) { System.IO.File.Delete(hosting.WebRootPath + "\\images\\profiles\\" + result.Entity.ID + ".jpg"); } } logger.Write(LOG_MODE.ACTION, "ID " + GetID() + " added new user(" + result.Entity.ID + ")"); } catch (Exception exc) { return(Send(new { status = "error", desc = exc.Message, number = exc.HResult, source = exc.Source, sTrace = exc.StackTrace })); } return(Send(new { status = "success" })); } case "update": { try { checker = new string[] { "id", "uid", "pwdNew", "pwdOld", "email", "status", "role", "customAccess", "clearPhoto" }; if (!CheckPayLoad(checker)) { return(ErrorInvalid()); } if (!CheckAccess(ACCESS.USER_EDIT)) { return(ErrorAccess()); } if (!ModelState.IsValid) { return(ErrorBadReq()); } var cekUser = await db.users.SingleOrDefaultAsync(user => user.ID == Convert.ToInt32(Request.Form["id"])); if (cekUser == null) { return(ErrorUserNotFound()); } Simple3Des des = new Simple3Des(cekUser.Username); if (cekUser.Password != des.EncryptData(Request.Form["pwdOld"])) { return(Send(new { status = "error", desc = "Old password didn't match" })); } if (cekUser.Username != Request.Form["uid"]) { var cekUserExist = await db.users.SingleOrDefaultAsync(user => user.Username == Request.Form["uid"]); if (cekUserExist != null) { return(ErrorUserExist()); } } des = new Simple3Des(Request.Form["uid"]); cekUser.Username = Request.Form["uid"]; cekUser.Password = des.EncryptData(Request.Form["pwdNew"]); cekUser.Email = Request.Form["email"]; cekUser.Status = Convert.ToBoolean(Request.Form["status"]); cekUser.ID_Group = Request.Form["role"] == "null" || Request.Form["role"] == "undefined" ? 0 : Convert.ToInt32(Request.Form["role"]); cekUser.Access = (string)Request.Form["customAccess"] == "null" ? "" : (string)Request.Form["customAccess"]; var result = db.users.Update(cekUser); if (result.State == EntityState.Modified) { await result.Context.SaveChangesAsync(); } else if (result.State == EntityState.Unchanged) { return(Send(new { status = "error", desc = "Can't edit existing User, due to state is remainly unchanged" })); } if (Request.Form["clearPhoto"] == "true") { if (System.IO.File.Exists(hosting.WebRootPath + "\\images\\profiles\\" + cekUser.ID + ".jpg")) { System.IO.File.Delete(hosting.WebRootPath + "\\images\\profiles\\" + cekUser.ID + ".jpg"); } } else { if (files.Count == 1) { var fStream = new FileStream(hosting.WebRootPath + "\\images\\profiles\\" + cekUser.ID + ".jpg", FileMode.Create); await files[0].CopyToAsync(fStream); fStream.Dispose(); fStream = null; } } logger.Write(LOG_MODE.ACTION, "ID " + GetID() + " commit update to user(" + result.Entity.ID + ")"); } catch (Exception exc) { return(Send(new { status = "Error", desc = exc.Message, number = exc.HResult, source = exc.Source, sTrace = exc.StackTrace })); } return(Send(new { status = "success" })); } case "delete": { try { checker = new string[] { "id" }; if (!CheckPayLoad(checker)) { return(ErrorInvalid()); } if (!CheckAccess(ACCESS.USER_DELETE)) { return(ErrorAccess()); } if (!ModelState.IsValid) { return(ErrorBadReq()); } var cekUser = await db.users.SingleOrDefaultAsync(user => user.ID == Convert.ToInt32(Request.Form["id"])); if (cekUser == null) { return(ErrorUserNotFound()); } if (GetID() == cekUser.ID) { return(Send(new { status = "error", desc = "You can't delete yourself" })); } var result = db.users.Remove(cekUser); if (result.State == EntityState.Deleted) { result.Context.SaveChanges(); } else if (result.State == EntityState.Unchanged) { return(Send(new { status = "error", desc = "Can't delete existing User, due to state is remainly unchanged" })); } logger.Write(LOG_MODE.ACTION, "ID " + GetID() + " delete user(" + result.Entity.ID + ")"); } catch (Exception exc) { return(Send(new { status = "Error", desc = exc.Message, number = exc.HResult, source = exc.Source, sTrace = exc.StackTrace })); } return(Send(new { status = "success" })); } case "change_pw": { try { checker = new string[] { "new", "old" }; if (!CheckPayLoad(checker)) { return(ErrorInvalid()); } if (!IsAuthenticated()) { return(ErrorAccess()); } if (!ModelState.IsValid) { return(ErrorBadReq()); } var cekUser = await db.users.SingleOrDefaultAsync(user => user.ID == GetID()); if (cekUser == null) { return(ErrorUserNotFound()); } Simple3Des des = new Simple3Des(cekUser.Username); if (cekUser.Password != des.EncryptData(Request.Form["old"])) { return(Send(new { status = "error", desc = "Old password didn't match" })); } cekUser.Password = des.EncryptData(Request.Form["new"]); var result = db.users.Update(cekUser); if (result.State == EntityState.Modified) { await result.Context.SaveChangesAsync(); } else if (result.State == EntityState.Unchanged) { return(Send(new { status = "error", desc = "Can't change password, due to state is remainly unchanged" })); } } catch (Exception exc) { return(Send(new { status = "Error", desc = exc.Message, number = exc.HResult, source = exc.Source, sTrace = exc.StackTrace })); } return(Send(new { status = "success" })); } /*case "checker": { * if (!CheckPayLoad(new string[] { * "uid" * })) return ErrorInvalid(); * return ""; * }*/ default: return(ErrorInvalid()); } }
static void Main(string[] args) { // Set Default Argument values bool quiet = false; bool debug = false; string sharepointUrl = null; Uri sharepointUri = null; string username = null; string password = null; bool useIntegratedAuth = true; string disk = null; bool mount = false; double expire = 0; string homedir = ""; Simple3Des dec = new Simple3Des("A$hbySchool1"); //Parse args Args CommandLine = new Args(args); if (CommandLine["m"] != null) { OtherMaps(false, CommandLine); } else { if (CommandLine["s"] == null) { Console.WriteLine("Error: SharePoint URL not specified !\n\nUsage: Cookie365 -s URL [-u [email protected] | -d domain.com] [-p {password}] [-quiet] [-mount [disk] [-homedir]]"); } else { try { // Retrieve SharePoint URL and Create URI sharepointUrl = CommandLine["s"]; sharepointUri = new Uri(sharepointUrl); // If username is specified use it, otherwise get the user UPN from AD if (CommandLine["u"] != null) { username = CommandLine["u"]; } else { username = System.DirectoryServices.AccountManagement.UserPrincipal.Current.UserPrincipalName; if (username != null) { if (CommandLine["d"] != null) { username = username.Split('@')[0] + "@" + CommandLine["d"]; } } else { Console.WriteLine("Username cannot be empty"); return; } } // If password is specified, use it, otherwise try integrated authentication if (CommandLine["p"] != null) { password = dec.DecryptData(CommandLine["p"]); useIntegratedAuth = false; } // Set the flag for quiet mode if (CommandLine["quiet"] != null) { quiet = true; } else if (CommandLine["debug"] != null) { debug = true; } // If asked to mount sharepoint as a share disk = CommandLine["mount"]; if (disk != null) { mount = true; if (disk == "true") { disk = "*"; } } if (CommandLine["expire"] != null) { expire = Convert.ToDouble(CommandLine["expire"]); } if (CommandLine["homedir"] != null) { String user = username.Split('@')[0]; String domain = username.Split('@')[1]; homedir = "DavWWWRoot\\personal\\" + user + "_" + domain.Split('.')[0] + "_" + domain.Split('.')[1] + "_" + domain.Split('.')[2] + "\\Documents"; } // if not quiet, display parameters if (!quiet) { // Message Console.WriteLine("============= Cookie365 v0.7 - (C)opyright 2014-2017 Fabio Cuneaz =============\n"); Console.WriteLine("SharePoint URL: " + sharepointUrl); Console.WriteLine("User: "******"Use Windows Integrated Authentication: " + useIntegratedAuth.ToString()); if (homedir != "") { Console.WriteLine("HomeDir: " + homedir); } if (mount) { Console.WriteLine("Mount as disk: " + disk); } } // Run Asynchronously and wait for cookie retrieval RunAsync(sharepointUri, username, password, useIntegratedAuth, !quiet, debug).Wait(); // If if (SpoAuthUtility.Current != null) { if (!quiet) { Console.Write("Setting Cookies in OS..."); } try { // Create the cookie collection object for sharepoint URI CookieCollection cookies = SpoAuthUtility.Current.cookieContainer.GetCookies(sharepointUri); // Extract the base URL in case the URL provided contains nested paths (e.g. https://contoso.sharepoint.com/abc/ddd/eed) // The cookie has to be set for the domain (contoso.sharepoint.com), otherwise it will not work String baseUrl = sharepointUri.Scheme + "://" + sharepointUri.Host; if (InternetSetCookie(baseUrl, null, cookies["FedAuth"].ToString() + "; Expires = " + cookies["FedAuth"].Expires.AddMinutes(expire).ToString("R"))) { if (InternetSetCookie(baseUrl, null, cookies["rtFA"].ToString() + "; Expires = " + cookies["rtFA"].Expires.AddMinutes(expire).ToString("R"))) { if (!quiet) { Console.WriteLine("[OK]. Expiry = " + cookies["FedAuth"].Expires.AddMinutes(expire).ToString("R")); } if (mount) { try { String cmdArgs = "/c net use " + disk + " \\\\" + sharepointUri.Host + "@ssl" + sharepointUri.PathAndQuery.Replace("/", "\\") + homedir; if (!quiet) { Console.Write("Mounting Share..." + cmdArgs); } System.Diagnostics.Process Process = new System.Diagnostics.Process(); Process.StartInfo = new System.Diagnostics.ProcessStartInfo("cmd", cmdArgs); Process.StartInfo.RedirectStandardOutput = true; Process.StartInfo.UseShellExecute = false; //Process.StartInfo.CreateNoWindow = true; Process.Start(); Process.WaitForExit(); String output = Process.StandardOutput.ReadToEnd(); if (!quiet) { Console.WriteLine("[OK]"); Console.WriteLine(output); } } catch (Exception e) { Console.WriteLine("[ERROR Mounting Share]:" + e.Message); } } } } } catch (Exception e) { Console.WriteLine("[ERROR setting Cookies]:" + e.Message); } } } catch (Exception e) { Console.WriteLine("[ERROR]:" + e.Message); } } } }