|
|
Thanks alot! This helps.
Have a nice weekend! ;)
|
|
|
|
|
Hi,
I want to encrypt a password and store the encrypted version in the database. then when the user logs in, I want to decrypt the user password and match with the entered password. I read about DESCryptoServiceProvider, but still i am not able to understand it. Can someone send a link of article which is easy to understand/provide a piece of code here. It would be great for me.
Thanks
|
|
|
|
|
Hi,
If you want to store a password in database, I suggest you use a 'One-Way Hash' algorythm.
These are un-reversable encryption algorythms, hence the name one-way. Then you follow these steps to authenticate your users:
1. User Registers, Username and Hashed Password are stored in DB.
2. User types in Username and Password. P = password
3. The Software encrypts the Users Password with a One-Way Hash. P1 = Hash(P)
4. The Software queries the database and finds the password of the user (Storing Hashed in the database). P2 = database_pass
5. If the Hashed Pass in the DB and Hashed Pass the user typed in Match, Allow Login. If P1 == P2 then Login else Fail (remeber P1 = Hash(P))
Try this code to generate a one-way hash of a password.
-------------------------------------------------------------------------------
private Byte[] GetByteArray( String originalString )
{
Char[] charArray = originalString.ToCharArray();
Byte[] byteArray = new Byte[charArray.Length];
for ( int i=0; i<byteArray.Length; i++ )
{
byteArray[i] = Convert.ToByte( charArray[ i ] );
}
return byteArray;
}
/// <summary>
/// Creates a one-way SHA1 hash of the pt string
/// </summary>
/// <param name="pt">Plaintext to Hash</param>
/// <returns>Ciphertext string</returns>
public string Hash(string pt)
{
//Implement SHA1 Hashing Algorythm (40 Bytes / 320 bits)
byte[] data = new byte[40];
byte[] hash = new byte[40];
while (pt.Length % 4 != 0) pt += "g";
data = Convert.FromBase64String(pt);
SHA1 sha = new SHA1CryptoServiceProvider();
hash = sha.ComputeHash(data);
return Convert.ToBase64String(hash);
}
-------------------------------------------------------------------------------
Thanx!
Dave Shaw
History admires the wise, but elevates the brave. - Edmund Morris
|
|
|
|
|
Thanks a lot
|
|
|
|
|
Hi - I'd like to dynamicaly move a button during runtime.
I've tried changing the control's Control.Location.X and .Y but get the error:
Cannot modify the return value of 'System.Windows.Forms.Control.Location' because it is not a variable.
Is there a way to move a control at run time?
Thanks, mutty
|
|
|
|
|
How about Control.Left or control.Top?
Pompiedompiedom...
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick
|
|
|
|
|
|
Well and if you want to know why you cannot change it: open reflector and see that the Location property returns the following:
return new Point(this.x, this.y);
So it is returning a new point object. If you anyway want to change the location of the control using the Location property you should feed it a new Point :
Control.Location = new Point(X,Y);
regards,
Gidon
|
|
|
|
|
Is there a way to find out the Windows version of a machine on the network in C#? I just want the Windows version (9x, XP, etc) and which service pack.
|
|
|
|
|
Take a look at WMI -- you can access it with script (VBScript, JScript, Python, Ruby, etc.) or even directly from C# with a little interop. Check out Scriptomatic[^] and look around that same vicinity of TechNet for more WMI information.
Matt Gerrans
|
|
|
|
|
i need to create a 'window dialog' in .showdialog() for user data input.
i can made it using window form or a component, but i've to do a choose.
What is better?
|
|
|
|
|
How can i count the number of lines in a string also the number of bytes in a string?
|
|
|
|
|
The number of lines in a string is the number of occurrences of Environment.NewLine + 1 . As the string class does not contain a method to count substrings you would probably have to run a for-loop over each char in the string and count.
The number of bytes of a string should be string.Length * sizeof(char) .
|
|
|
|
|
To Count line in string
Regex rx=new Regex(Environment.NewLine);
MatchCollection mc=rx.Matches(textBox1.Text);
int lineCount=mc.Count;
Note:if the last two chars of string is not Environment.Newline
the line count will be decreased by 1 so you can check
that last two chars in the string is Environment.NewLine
If not add it
To Get the bytes in string use Encoding class
and select Encoding Format you work with
For Example
int cb=Encoding.UTF8.GetByteCount(textBox1.Text);
MCAD
-- modified at 9:40 Saturday 27th August, 2005
|
|
|
|
|
Just to make publicity... :-P
Some files can be Mac and Linux files, and they can have different "NewLines"... Look at this program I made, get the source code if you want!
http://www.sulfurmidis.com/sulfursoft/software/tfc.html[^]
Darth_Sulfur (Sulfurik)
http://www.sulfurmidis.com
http://www.sulfursoft.tk
ftp://tsfc.ath.cx
http://tsfc.ath.cx
hotline://tsfc.ath.cx
|
|
|
|
|
The easiest way of counting the number of line breaks would be to remove them from the string and then check the difference in size:
lines = 1 + ((Len(text) - Len(text.Replace(Environment.NewLine, string.Empty))) / Len(Environment.NewLine));
---
b { font-weight: normal; }
-- modified at 11:28 Saturday 27th August, 2005
|
|
|
|
|
To read the number of bytes, you can use Systm.Text.Encoding.Default.GetByteCount .
The most accurate way to count lines would probably be to use StringReader.ReadLine , but if that's too much overhead, try this function:
static int LineCount(string str)
{
int lines = 1;
for(int i = 0; i < str.Length; i++)
{
if(str[i] == '\r' || str[i] == '\n')
{
if(i+1 < str.Length && (str[i] == '\r' && str[i+1] == '\n'))
i++;
lines++;
}
}
return lines;
}
-- modified at 19:13 Monday 29th August, 2005
|
|
|
|
|
hi,
how can i read information from a excel table...for example i want to read the row A1 and to write another value back....
any idea to do that?
bye
|
|
|
|
|
|
hi, i compiled this sample!
and i got that error:
private Excel.Application ExcelObj = null;
error CS0246: The type or namespace name 'Excel' could not be found (are you missing a using directive or an assembly reference?)
but the Interop.Excel Assembly = icrosoft Excel 11.0 Object Library is in the projekt!! hmmm...
cu
|
|
|
|
|
I've made a little application for opening pictures using pictureboxes. I've used File Type Editor to connect my app with .bmp. .jpg, . gif etc. file types. After instalation, when I doubleclick a picture file, my app runs, but there is no picture in pictureBox1. I know I have to do something with Arguments property, but I dont know what. I've tried:
public static void Main(string[] args)
{
Application.Run(new Form1());
args=Environment.GetCommandLineArgs();
foreach (string arg in args)
{
fajl=fajl+arg;
}
pictureBox1.Image=Image.FromFile(fajl);
}
How to make doubleclicked file apear in pictureBox1??
please help!
|
|
|
|
|
The line after Application.Run(new Form1()); will not be executed untill you close the form.You should put your code either in Form1 constructor or in form_load event handler or in form_activate event handler
for example:
public static void Main(string[] args)
{
Application.Run(new Form1(args));
}
private Form1(string[] args)
{
foreach(string arg in args)
fajl+=arg;
pictureBox1.Image=Image.FromFile(fajl);
}
P.S. remember that Form1 constructor is an instance member (not a classifier) then none of the variables within it can be static or you should use Form1.variableName to refer to them.
|
|
|
|
|
Thank you, thank you, thank you
It works perfectly now ;);)
|
|
|
|
|
I have an Visual C#.NET 2003 and want to develop a "Smart Device Application", but it isn't contained in the New Project dialog.
I've also installed:
.NET Compact Framework
Microsoft Pocket PC 2003 SDK
Mobile Application Development Toolkit
But I'm still not able to create that mysterious "Smart Device Application"
If I have some TOO CHEAP edition of VS IDE, is there some alternative IDEs which support mobile development?
|
|
|
|