如何在c#中限制GUID的长度来发送密码 [英] how to limit the length of GUID in c# to send password
本文介绍了如何在c#中限制GUID的长度来发送密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何限制c#中GUID的长度以发送密码
how to limit the length of GUID in c# to send password
推荐答案
如果您要生成随机密码,为什么不使用以下方法,这是.Net Framework(从V2开始)
System.Web.Security.Membership.GeneratePassword
见这里;
http: //msdn.microsoft.com/en-us/library/ms152017 [ ^ ]
If you are looking to generate random passwords why not use the following method which is part of the .Net Framework (from V2 onwards)
System.Web.Security.Membership.GeneratePassword
See here;
http://msdn.microsoft.com/en-us/library/ms152017[^]
如果您使用Guid生成随机密码,则使用Substring()函数获取其中的一部分。 />
If you are using the Guid to generate a random password, then use the Substring() function to get a part of it.
string strPassword = Guid.NewGuid().ToString("N").Substring(0, 12);
但是,请记住,Guid是唯一的,它的一部分可能不是唯一的。
http://msdn.microsoft.com/en-us/library/s6tk2z69 [ ^ ]
string strPassword = Guid.NewGuid()。ToString()。Substring(0,Guid.NewGuid()。ToString()。IndexOf( - ));
这将生成一个唯一的字母数字密码。
例如,如果生成的GUID是0f8fad5b-d9cb-469f-a165-70867728950e,那么它将只检索0f8fad5b。它对密码生成很有用。
试试这个..
string strPassword = Guid.NewGuid().ToString().Substring(0, Guid.NewGuid().ToString().IndexOf("-"));
This will generate an unique alpha numeric password.
For example if the generated GUID is "0f8fad5b-d9cb-469f-a165-70867728950e" then it will retrieve only "0f8fad5b". It will be useful for password generation.
Try this..
这篇关于如何在c#中限制GUID的长度来发送密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文