public static string createQRCode(string sceneName, string host) { NameBasedGenerator uuidCreator = new NameBasedGenerator(HashType.SHA1); ImageFormat imageFormat = ImageFormat.Png; string markerUUID = uuidCreator.GenerateGuid(sceneName + DateTime.Now).ToString(); string url = host + "/QRCode/Open?uuid="; string content = url + markerUUID; QrCode qr = QrCode.EncodeText(content, QrCode.Ecc.Medium); string dir = Directory.GetCurrentDirectory(); string filename = markerUUID + "." + imageFormat.ToString(); var path = Path.Combine( dir, "static", "content", "marker", filename); using (var stream = new FileStream(path, FileMode.Create)) using (var bitmap = qr.ToBitmap(40, 1)) { bitmap.Save(stream, imageFormat); } return(filename); }
public ScenesController(IHttpContextAccessor httpContextAccessor, IMongoClient client) { var database = client.GetDatabase(Backend.DatabaseName); _scenes = database.GetCollection <Scene>("Scenes"); uuidCreator = new NameBasedGenerator(HashType.SHA1); _host = httpContextAccessor; host = httpContextAccessor.HttpContext.Request.Host.Value; prot = httpContextAccessor.HttpContext.Request.Scheme; }
public void UUIDGenerated_InSameNameAndNameSpace_InDifferentTimes_ShouldBeSame(HashType hashType, UUIDNameSpace nameSpace) { var name = Guid.NewGuid().ToString(); using (var generator = new NameBasedGenerator(hashType)) { var first = generator.GenerateGuid(nameSpace, name); var second = generator.GenerateGuid(nameSpace, name); Assert.Equal(first, second); } }
public UploadController(IFileProvider fileProvider, IMongoClient client) { this.fileProvider = fileProvider; uuidCreator = new NameBasedGenerator(HashType.SHA1); var database = client.GetDatabase("cmsXARCH"); _assets = database.GetCollection <Asset>("Assets"); _unis = database.GetCollection <University>("Universities"); _courses = database.GetCollection <Course>("Courses"); _studies = database.GetCollection <StudyProgramme>("StudyProgrammes"); _creators = database.GetCollection <Creator>("Creators"); }
public void UUIDGenerated_InWithSameName_InDifferentCustomNameSpace_ShouldBeDifferent(HashType hashType) { var name = Guid.NewGuid().ToString(); var firstNs = Guid.NewGuid(); var secondNs = Guid.NewGuid(); using (var generator = new NameBasedGenerator(hashType)) { var first = generator.GenerateGuid(firstNs, name); var second = generator.GenerateGuid(secondNs, name); Assert.NotEqual(first, second); } }
public void GeneratedUUID_ShouldHaveProperVersion(HashType hashType) { var name = Guid.NewGuid().ToString(); var nameSpace = Guid.NewGuid(); var expectedVersion = hashType == HashType.Md5 ? 0x30 : 0x50; using (var generator = new NameBasedGenerator(hashType)) { var guid = generator.GenerateGuid(nameSpace, name); var array = guid.ToByteArray(); Assert.Equal(expectedVersion, array[7] & 0xf0); } }
public MojangUser(string userName, string password) { JObject postdata = new JObject(); postdata["agent"] = new JObject(); postdata["agent"]["name"] = "Minecraft"; postdata["agent"]["version"] = 1; postdata["username"] = userName; postdata["password"] = password; postdata["clientToken"] = new NameBasedGenerator().GenerateGuid("OMCL").ToString(); postdata["requestUser"] = true; try { string data = Post.Post_Data("https://authserver.mojang.com/authenticate", postdata.ToString(), new System.Net.CookieContainer(), "utf-8", "", "application/json"); JObject result = JObject.Parse(data); if ((result["availableProfiles"] as JArray).Count == 0) { throw new NoUserProfileException(); } else { JObject profile = result["selectedProfile"] as JObject; this.uuid = profile["id"].ToString(); this.username = profile["name"].ToString(); this.cachedusername = this.username; SaveIcon(); this.Mail = userName; this.password = password; } } catch (Exception ex) { if (ex.Message.Contains("403")) { throw new IncorrectUserInfoException(); } else { throw; } } }
public NameBasedIdentityGenerator() { generator = new NameBasedGenerator(); }
public static Guid Create(Guid val) { using var generator = new NameBasedGenerator(HashType.Sha1); return(generator.GenerateGuid(UUIDNameSpace.Url, val.ToString())); }
public InjectUser(Uri authserver, string mail, string password) { this.authserver = authserver; string serverName = ""; try { JObject data = JObject.Parse(Post.Get_Data(authserver.ToString(), new System.Net.CookieContainer(), "utf-8", "")); serverName = data["meta"]["serverName"].ToString(); } catch (Exception ex) { Logger.LogError("I'm Authlib Injector PLUGIN:There is a F*****g Error:" + ex.GetType() + ":" + ex.Message + "\n" + ex.StackTrace); throw new IncorrectServerOrWebException(); } string tempu = authserver.AbsoluteUri; if (tempu.EndsWith(tempu)) { tempu = tempu.Substring(0, tempu.Length - 1); } string url = tempu + "/authserver/authenticate"; JObject postdata = new JObject(); postdata["agent"] = new JObject(); postdata["agent"]["name"] = "Minecraft"; postdata["agent"]["version"] = 1; postdata["username"] = mail; postdata["password"] = password; postdata["clientToken"] = new NameBasedGenerator().GenerateGuid("OMCL").ToString(); postdata["requestUser"] = true; try { string data = Post.Post_Data(url, postdata.ToString(), new System.Net.CookieContainer(), "utf-8", "", "application/json"); JObject result = JObject.Parse(data); if ((result["availableProfiles"] as JArray).Count == 0) { throw new NoUserProfileException(); } else { JObject profile = result["selectedProfile"] as JObject; this.uuid = profile["id"].ToString(); this.username = profile["name"].ToString(); this.cachedusername = this.username; SaveIcon(); this.Mail = mail; this.password = password; } } catch (Exception ex) { if (ex.Message.Contains("403")) { throw new IncorrectUserInfoException(); } else { throw; } } }