|
|
I've been poking around the web for a solution to this and perhaps I'm not looking in the right place, so I thought I'd post the question.
My C# Form prompts the user for a username, password, and domain. I'd like to verify that these values are the same as the currently logged in Windows user. I can get the Username and Domain name from the Environemt class, but I need to verify that the password given is correct as well.
Any help out there?
never mind I found it....
DirectoryEntry de = new DirectoryEntry("WinNT://"+Environment.MachineName+", computer",txtUsername.Text,txtPassword.Text);
try
{
Object o = de.NativeGuid;
this.DialogResult=DialogResult.OK;
}
catch(Exception)
{
this.DialogResult=DialogResult.Cancel;
}
finally
{
de.Close();
}
|
|
|
|
|
I don't think it's an easy think, because as I know windows make his own hash coding for the password and store it in a hidden system folder.
|
|
|
|
|
I don't care what the password is, I just want to validate it. The code snipet I included works....problem solved. Thanks for you reply though.
|
|
|
|
|
OK!
I understand, you only want to validate, but I think (till now) the password file is prtected by the OS.
Would you kind to send, or link the snipets for me, It's interested me.
Thanks
|
|
|
|
|
Look at the code in my original post....it works.
|
|
|
|
|
Hi all.
Casting problem here!
If I have the following code:
<br />
Type classType = typeof(MyDerivedClass);<br />
MyBaseClass o = Activator.CreateInstance(classType) as MyBaseClass;<br />
...<br />
o.SomeFunctionInDerivedClass();<br />
This all works fine and splendid. But if I have this code in a function, and I want to, at runtime, decide on the type of class being instantiated, how do I do the 'as' keyword explicit cast? I'm using 1.1 so can't use templates/whatever they are called.
TIA
Gizz
|
|
|
|
|
If the type of the class is decided at runtime, then you can't have code like
o.SomeFunctionInDerivedClass();
either. What you'd have to do is use reflection to invoke methods, something like
object obj = Activator.CreateInstance(passedType);
obj.GetType().InvokeMember("SomeFunctionInDerivedClass",...);
Of course, the type you instantiated might not have an "SomeFunctionInDerivedClass" method, it'll then result in an exception and you have to handle it. That's the price to pay for reflection, you lose compile time type safety.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
|
I'm trying to get an idea of where to start looking for info on doing this or if it's even possible:
I'm working with VistaDB and it doesn't support Unicode yet. They claim that text is stored as "Ansi" only. Let's say I have a Unicode string and want to store it into a text field in their database.
Is it conceivable that I can convert that string to something that will store in Ansi (may well be unreadable gibberish at that point, no problem) then de-convert it back to unicode upon retrieval?
I.E. take the 16 bit unicode characters from UTF-16, split them out into ANSI (which I'm guessing is good old single byte 8bit characters) save it and later retrieve it and reverse the process?
"A preoccupation with the next world pretty clearly signals an inability to cope credibly with this one."
|
|
|
|
|
Off the top of my head, you'll probably have to encode the Unicode string into something more 8-bit friendly, like Base64. Yeah, that should work... convert the Unicode string to an array of bytes (Convert.ToByte() ), pass that through the Convert.ToBase64String() method. You could then store the encoded string in your database. Just reverse the process to get it back out.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I never thought of that. I was thinking of some wizardry with UTF-8 or UTF-7 encoding and decoding, but that would work as well.
Thanks for the suggestion!
"A preoccupation with the next world pretty clearly signals an inability to cope credibly with this one."
|
|
|
|
|
Found it, for the elucidation of others it's dead simple:
//Convert to ascii 7 bit text for saving to a database that doesn't support unicode:
//(or smtp or whatever)
string u="Hindi: यूनिकोड क्या है?";
string encoded=Encoding.ASCII.GetString(Encoding.UTF7.GetBytes(u));
//which ends up looking like this:
//"Hindi: +CS8JQgkoCT8JFQlLCSE- +CRUJTQkvCT4- +CTkJSA-?"
//Converting back to unicode:
string decoded=Encoding.ASCII.GetString(Encoding.UTF7.GetBytes(u));
What's interesting is that apparently it delimits every string of text that contains characters outside the ascii code range so when you have a mixed string as above of English and Unicode it's more efficient to do it this way than to base64 the whole thing because it will only do the bits it needs to which is what applies in the app we're working on that will often contain mixed text.
"A preoccupation with the next world pretty clearly signals an inability to cope credibly with this one."
|
|
|
|
|
That's cool. I never had to deal with a case such as yours. Your solution is definately better than mine.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hey everyone,
I need a way to look at a compiled assembly and determine what variable types are allocated during a method call. Is there a way to do this in .NET, possibly using reflection? I've got an enterprise level application that uses a number of objects that implement IDisposable. Some of the coders have not been disposing of these objects when they are finished with them. I need some way to track down the methods where this is occurring. Any ideas?
Will
|
|
|
|
|
Look here: http://www.aisto.com/roeder/dotnet/[^]
It is just the best "reflecting" and decompiler program - a must-have!
You can explore the code and resources of any assembly in (almost) every .net language you want!
|
|
|
|
|
I hope this question don't win "The Most Stupid Question Of The Day" prize,
but I was just wondering if there is an easy way to import the macros from some
C header files (like CommCtrl.h) in C#. Cause they're very handy and the WinForms
controls don't provide all of the functionality of the Windows Shell controlls.
|
|
|
|
|
|
C# doesn't support header files and there is no utility to "import" them from other languages. You'll have to recode, by hand, what you want out of the header into C# code and make sure it ends up in an appropriate place in your code.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
OK, thanks for both replies.
The hidden idea in the question was also to find someone
that has already done that
|
|
|
|
|
The problem with writing a translator for this is it has no clue in what context translated code should be in and, therefore, can't predict where the new code should go.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Ok for a while now ive have been tring to save an object from my resources as a file on the hard drive. The object is a byte[]. You may have seen questions regarding this.
Recently i have tried to get it into a stream and then save the stream. But i had problems getting it into a stream, i got alot of help for this and am grateful, but after trying:
FileStream fs = rm.GetObject("outside") as FileStream;
I got rid of the error "specified cast is not valid", and obtained a new one "object reference not set to an instance of the object". In other words, the filestream (fs) is still null, even after making it equal my object.
Any ideas, help, large mallets... would be GREATLY GREATLY apreciated.
I have beem trying to get this to work for a total of about 10 hours over the past month, but i realy need to get this sorted soon.
If you have any ideas on how to save the object without getting it into a stream post them as well.
Thanks in advance for putting up with me!
|
|
|
|
|
OK, as I understand, you have a byte array (the bunary representation of some file) in
memory and you want to flush it to the disk. If that's the situation, I think I can help.
I recently wrote a similar class. Here's the SaveAs method:
_bytes is a byte[] array - a private class field.
<code>public void SaveAs(string filePath)
{
using(FileStream stream = System.IO.File.OpenWrite(filePath))
{
stream.Write(_bytes, 0, _bytes.Length);
}
}</code>
|
|
|
|
|
If rm.GetObject("outside") returns a byte[], then how do you expect to cast it to a FileStream. The 'as' operator casts an object if possible and returns null if it can't. The objects cannot be directly converted into each other therefore, fs is null.
The easiest stream you can create with a byte[] array is MemoryStream.
MemoryStream ms = new MemoryStream((byte[])rm.GetObject("outside"));
If your goal is to write a byte[] array to a file then try a pattern like this:
byte[] tmp = (byte[])rm.GetObject("outside");
FileStream fs = new FileStream(FILE_NAME, FileMode.CreateNew);
fs.Write(tmp,0,tmp.Length);
fs.Close();
|
|
|
|
|
hi,
im trying to get a http site using httprequest. the problem ist, whenever a site contains frames i get only one frame, not the whole site. what can i do?
this is part of my code:
string getSite(String url, String referer) {<br />
try<br />
{<br />
if (url.StartsWith("www")) {url="http://"+url;}<br />
CookieContainer CookieCont = new CookieContainer();<br />
HttpWebRequest req = (HttpWebRequest) HttpWebRequest.Create(url);<br />
if(this.boxUseProxy.Checked)<br />
{<br />
WebProxy proxyObject = new WebProxy(this.boxProxyHostname.Text.Trim());<br />
proxyObject.Credentials = new NetworkCredential(this.boxProxyUsername.ToString(), this.boxProxyPasswort.ToString(), "");<br />
<br />
proxyObject.BypassProxyOnLocal = true;<br />
<br />
GlobalProxySelection.Select = proxyObject;<br />
req.Proxy = WebProxy.GetDefaultProxy();<br />
req.Proxy=proxyObject;<br />
}<br />
<br />
req.Referer=referer;<br />
req.ProtocolVersion = HttpVersion.Version11;
req.AllowAutoRedirect = true;<br />
req.UserAgent = "Mozilla/4.0";<br />
req.CookieContainer = CookieCont;<br />
<br />
WebResponse result = req.GetResponse();<br />
Stream ReceiveStream = result.GetResponseStream();<br />
Encoding encode = System.Text.Encoding.GetEncoding("ISO-8859-1");<br />
StreamReader sr = new StreamReader( ReceiveStream, encode );<br />
<br />
return(sr.ReadToEnd());<br />
}<br />
catch(WebException ex)<br />
{<br />
string message = ex.Message;<br />
HttpWebResponse response = (HttpWebResponse)ex.Response;<br />
if(null != response)<br />
{<br />
message = response.StatusDescription;<br />
response.Close();<br />
}<br />
txtStatus.Text += message;<br />
return("Internal error opening Site\r\n"+message.ToString()+"\r\n");<br />
}<br />
catch(Exception ex)<br />
{<br />
txtStatus.Text += ex.Message;<br />
return("Internal error opening Site\r\n"+ex.Message+"\r\n");<br />
}<br />
<br />
}<br />
|
|
|
|