public IActionResult Register(RegVal model) { if (ModelState.IsValid) { User existingUser = _context.Users.SingleOrDefault(u => u.username == model.username); if (existingUser != null) { ModelState.AddModelError("username", "Username is already in use."); return(View("Index")); } PasswordHasher <User> hasher = new PasswordHasher <User>(); User newUser = new User() { username = model.username, }; newUser.password = hasher.HashPassword(newUser, model.password); _context.Add(newUser); _context.SaveChanges(); newUser = _context.Users.SingleOrDefault(u => u.username == model.username); HttpContext.Session.SetInt32("id", newUser.id); HttpContext.Session.SetString("name", newUser.username); return(RedirectToAction("Main")); } return(View("Index")); }
private bool GetAutoLoadAtLogonRegistry() { string RegVal; bool result; try { // Check if the CurrentUser AutoRun Registry contains the KeepMeBusy entry using (RegistryKey reg = Registry.CurrentUser.OpenSubKey(CurrentUserAutoRunRegistry)) { RegVal = (string)(reg.GetValue("KeepMeBusy", null)); reg.Close(); } } catch (Exception) { RegVal = null; } if (String.IsNullOrEmpty(RegVal)) { result = false; // AutoRun not enabled } else { if (RegVal.Equals(this.AssemblyLocation, StringComparison.OrdinalIgnoreCase)) { result = true; // AutoRun is enabled and the path is correct } else { result = SetAutoLoadAtLogonRegistry(true); // AutoRun is enabled but the app .exe file has probably been moved. Fix it. } } this._AutoRunAtLogon = result; return(result); }
//set IE version to latest version private void SetIEKeyforWebBrowserControl(string appName) { RegistryKey Regkey = null; try { int BrowserVer, RegVal; // get the installed IE version using (WebBrowser Wb = new WebBrowser()) BrowserVer = Wb.Version.Major; // set the appropriate IE version if (BrowserVer >= 11) { RegVal = 11001; } else if (BrowserVer == 10) { RegVal = 10001; } else if (BrowserVer == 9) { RegVal = 9999; } else if (BrowserVer == 8) { RegVal = 8888; } else { RegVal = 7000; } // For 64 bit machine if (Environment.Is64BitOperatingSystem) { Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\\Wow6432Node\\Microsoft\\Internet Explorer\\MAIN\\FeatureControl\\FEATURE_BROWSER_EMULATION", true); } else //For 32 bit machine { Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", true); } //If the path is not correct or //If user't have priviledges to access registry if (Regkey == null) { MessageBox.Show("Registry Key for setting IE WebBrowser Rendering Address Not found. Try running the program with administrator's right."); return; } string FindAppkey = Convert.ToString(Regkey.GetValue(appName)); //Check if key is already present if (FindAppkey == RegVal.ToString()) { Regkey.Close(); return; } Regkey.SetValue(appName, RegVal, RegistryValueKind.DWord); } catch (Exception ex) { MessageBox.Show("Registry Key for setting IE WebBrowser Rendering failed to setup"); MessageBox.Show(ex.Message); } finally { //Close the Registry if (Regkey != null) { Regkey.Close(); } } }
public static Boolean Registration(Frequency band, short channel, int x, int y, int sleepTime) { if (channel == 0) // In case if trys to send data in incorrect channel { return(false); } RegKey Tk = null; bool ret = false; RegVal ver = null; try { if (_packets.Count == 0) { if (_T != null) { lock (_T) { _T.Clear(); } } } Tk = new RegKey(band, channel); if (_T.ContainsKey(Tk)) { ArrayList _temp = (ArrayList)_T[Tk]; if (_temp != null) { foreach (var obj in _temp) { RegVal _tV = (RegVal)obj; if (getDistance(x, y, _tV.x, _tV.y) < ReceiveDistance) { return(false); } } ver = new RegVal(x, y); _temp.Add(ver); lock (_T) { _T[Tk] = _temp; } ret = true; return(ret); } else { ArrayList _tempArrL = new ArrayList(); ver = new RegVal(x, y); _tempArrL.Add(ver); lock (_T){ _T.Add(Tk, _tempArrL); } ret = true; return(ret); } } else { ArrayList _tempArrL = new ArrayList(); ver = new RegVal(x, y); _tempArrL.Add(ver); lock (_T){ _T.Add(Tk, _tempArrL); } ret = true; return(ret); //Thread newThread = new Thread(() => Unregister(Tk, ver)); //newThread.Start(); } } catch (Exception ex) { if (DebugLogEnabled) { AddToLog("[Registration] Exception:" + ex.Message); } return(false); } finally { if (ret) { //Thread.Sleep(1); Thread.Sleep(new TimeSpan(sleepTime * _MediumSendDataRatio * 110)); ArrayList _temp = (ArrayList)_T[Tk]; try { lock (_T) { _temp.Remove((RegVal)ver); if (_temp.Count > 0) { _T[Tk] = _temp; } else if (_T.Count == 1) { _T.Clear(); } else { _T.Remove(Tk); } } } catch (Exception ex) { if (DebugLogEnabled) { //Console.WriteLine("Unregister:" + ex.Message); MessageBox.Show("Unregister:" + ex.Message); AddToLog("Unregister:" + ex.Message); } _T.Remove(Tk); _T.Clear(); } } } //return (true); }