guid

Guid.NewGuid().GetHashCode() for DB

泄露秘密 提交于 2019-12-07 06:33:01
问题 Would this be reliable for using as an ID for data storage(SQL Server)? I would use a guid but I prefer a numeric value. 回答1: Would this be reliable for using as an ID for data storage(SQL Server)? No. GUIDs are 128-bit but hashcodes are 32-bit. Therefore, there are necessarily collisions. It may be unlikely that you ever encounter one, but you are not guaranteed to never encounter one. What you want for reliability is a guarantee that you never encounter a collision. If you insist on using

c# System.guid does not contain a definition for Parse

拜拜、爱过 提交于 2019-12-07 05:20:47
问题 AT.Anchor = System.Guid.Parse(DataBinder.Eval(e.Item.DataItem, "Anchor").ToString()); This throws: 'System.Guid' does not contain a definition for 'Parse' When I try and build it. But it runs fine, any idea how I can handle this better? Edit Here is a section of my web.config <compilation defaultLanguage="c#" debug="true"> <assemblies> <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture

How to Convert Long to Guid and Vice Versa?

跟風遠走 提交于 2019-12-07 02:28:39
问题 Is this even possible? I don't even think it is, but I saw some code that was trying to do it. However, my unit tests showed that it was not working. I did see some similar thoughts: Converting GUID to Integer and Back Converting System.Decimal to System.Guid Just for clarification. The Guid creation is outside of my control; therefore, I can't just store the value in one of the Guid sets. 回答1: A GUID is 16 bytes long. A "long" is often understood as being 64 bits (i.e. 8 bytes) long. You

Are GUIDs generated on Windows 2003 safe to use as session IDs?

ぃ、小莉子 提交于 2019-12-07 01:27:28
问题 My web application operates only over SSL and sets a time limited cookie for each user after they successfully login with a username and password. The biggest weaknesses in the system are one compromising an existing user's cookie. And two guessing a session ID GUID. I know of mechanisms for the first weakness but I'm wondering how much I need to worry about the chance of an attacker guessing a session ID GUID based on a GUID they have previously obtained by logging into an account they have

唯一编号算法:生成GUID

旧巷老猫 提交于 2019-12-07 00:25:00
你有过生成不重复编号的想法吗?比如做一个自动保存网页图片的工具,要保证保存的图片不互相覆盖,一个想法是使用一个计数器从1开始递增,但是这样还有问题,比如我们无法保证磁盘中以前没有可能造成重复的图片文件。 那么就来看看GUID算法吧。 GUID(全局统一标识符)是指在一台机器上生成的数字,它保证对在同一时空中的所有机器都是唯一的。它使用网卡MAC、地址、纳秒级时间、芯片ID码和许多可能的数字,这样保证每次生成的GUID永远不会重复,无论是同一个计算机上还是不同的计算机。 GUID长什么样呢? {C7B1AFCC-810E-46d0-8157-09FC488D4C71} 看起来挺古怪的吧。在 Windows 平台上,GUID 应用非常广泛:注册表、类及接口标识、数据库、甚至自动生成的机器名、目录名等。 不用担心GUID的性能问题,因为它生成过程是采用MAC地址、机器时钟等计算的,没有并发问题,所以它一点都不比自增计数器的慢,有时候甚至更快。 讲了一大堆理论,在程序中怎么生成GUID呢? 非常简单,调用CoCreateGuid函数即可,它定义在objbase.h这个头文件中。 核心调用代码: //--生成GUID void generate_guid(TCHAR* guid_string) { GUID guid; strcpy(guid_string,""); if(

JavaScript生成GUID的算法

元气小坏坏 提交于 2019-12-07 00:24:34
全局唯一标识符(GUID,Globally Unique Identifier)也称作 UUID(Universally Unique IDentifier) 。 GUID是一种由算法生成的二进制长度为128位的数字标识符。GUID 的格式为“xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”,其中的 x 是 0-9 或 a-f 范围内的一个32位十六进制数。在理想情况下,任何计算机和计算机集群都不会生成两个相同的GUID。 GUID 的总数达到了2^128(3.4×10^38)个,所以随机生成两个相同GUID的可能性非常小,但并不为0。GUID一词有时也专指微软对UUID标准的实现。 算法1 1 2 3 4 5 6 7 8 9 10 11 12 13 function uuid() { var s = []; var hexDigits = "0123456789abcdef" ; for ( var i = 0; i < 36; i++) { s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1); } s[14] = "4" ; // bits 12-15 of the time_hi_and_version field to 0010 s[19] = hexDigits.substr(

获得唯一标识符——时间戳、GUID

只愿长相守 提交于 2019-12-07 00:24:14
引言: 在项目中我们常常需要获得一些唯一标识,除了数据库的自增字段,我们还可以用时间戳和获取GUID的方式,现总结代码如下,以备后需。 方法: 写好调用即可。(代码如下) 代码(C#版): 时间戳: /// <summary> /// 获得时间戳 /// </summary> public static string GetTimeStamp() { TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0); return Convert.ToInt64(ts.TotalSeconds).ToString(); } GUID: /// <summary> /// 获得GUID串 /// </summary> /// <returns></returns> protected string getGUID() { long i = 1; foreach (byte b in Guid.NewGuid().ToByteArray()) i *= ((int)b + 1); return string.Format("{0:x}", i = DateTime.Now.Ticks); } 小结: 一些有用简单的代码,增加自己的代码量。 把积累做在平时,需要时高效工作。 来源: CSDN 作者: Francis

生成guid

倖福魔咒の 提交于 2019-12-07 00:23:29
JavaScript生成GUID的算法 全局唯一标识符(GUID,Globally Unique Identifier)也称作 UUID(Universally Unique IDentifier) 。 GUID是一种由算法生成的二进制长度为128位的数字标识符。GUID 的格式为“xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”,其中的 x 是 0-9 或 a-f 范围内的一个32位十六进制数。在理想情况下,任何计算机和计算机集群都不会生成两个相同的GUID。 GUID 的总数达到了2^128(3.4×10^38)个,所以随机生成两个相同GUID的可能性非常小,但并不为0。GUID一词有时也专指微软对UUID标准的实现。 算法1 1 2 3 4 5 6 7 8 9 10 11 12 13 function uuid() { var s = []; var hexDigits = "0123456789abcdef" ; for ( var i = 0; i < 36; i++) { s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1); } s[14] = "4" ; // bits 12-15 of the time_hi_and_version field to 0010 s[19]

JS生成GUID和传参乱码

末鹿安然 提交于 2019-12-07 00:23:06
--32位ID var id = replace (java.util.UUID.randomUUID(), "-" , "" ); 全大写: var ID = replace(java.util.UUID.randomUUID(),”-“,”“).toUpperCase(); 全小写: var id = replace(java.util.UUID.randomUUID(),”-“,”“).toLowerCase(); --36位ID var id = replace (java.util.UUID.randomUUID(), "_" , "" ); –中文乱码问题 url = encodeURI(url); –JS对汉字的编码和转码 encodeURI( encodeURI(lm. getValueByName( "name" ) ) ) decodeURI(date) 来源: CSDN 作者: 俊不见高堂明镜 链接: https://blog.csdn.net/u010758605/article/details/50944046

GUID生产类

久未见 提交于 2019-12-07 00:22:54
public class GUID { private static Date date = new Date(); private static StringBuilder buf = new StringBuilder(); private static int seq = 0 ; //最好设置成5位,因前段JS无法获取超过14位的长整型,调整为2位递增 //循环终止数 private static final int ROTATION = 99 ; public static String getGuid () { return UUID.randomUUID().toString(); } public static synchronized long next () { if (seq > ROTATION) seq = 0 ; buf.delete( 0 ,buf.length()); date.setTime(System.currentTimeMillis()); String str = String.format( "%1$ty%1$tm%1$td%1$tk%1$tM%1$tS%2$02d" ,date,seq++); return Long.parseLong(str); } } String. format ( " %1 $ty %1 $tm %1 $td