views:

110

answers:

2

How can we hide (invisible) some CodeBehind lines (for example a class) from other developers in a common project?

I asked this question because today we were working on email codes and we wanted to send an email to all of programmers emails therewith sending an Email to our common web site email.

How can we hide our passwords from each other?

Is it possible to make 3 classess (for sending emails to 3 web developers) and hide or invisible those classes(class file or codebehind lines) and so each peogrammer can see only his class?

thanks in advance///

the email code is like :

protected void Button1_Click(object sender, EventArgs e)
{

    //create mail message
    MailMessage mail = new MailMessage();
    //set the address
    mail.From = new MailAddress("[email protected]");
    mail.To.Add("[email protected]");
    //set the content
    mail.Subject = "Project email";
    mail.Body = "Hello World!";

    //send the message
    SmtpClient smtp = new SmtpClient();
    smtp.UseDefaultCredentials = false;
    smtp.Credentials = new System‎‎.Net‎‎.NetworkCredential("[email protected]", "pass");
    smtp.Host = "smtp.gmail.com";
    smtp.Port = 587;             
    smtp.EnableSsl = true;





    try
    {

        smtp.Send(mail);
        Button1.Text = "sent";
    }
    catch (System‎‎.Net.Mail.SmtpException exp)
    {
        Label1.Text = exp.ToString();
    }

}
+1  A: 

You should not be hard coding passwords into classes, you should put this kind of information in a config file. You can encrypt or hash the password for extra security. I am also not sure why you would need a password to send someone an email.

you could do something like:

string strEmail = System.Configuration.ConfigurationManager.AppSettings["Email"];
string strPassword = System.Configuration.ConfigurationManager.AppSettings["EmailPassword"];
smtp.Credentials = new System‎‎.Net‎‎.NetworkCredential(strEmail,strPassword )

You could the store the email and password in the web/app.config file as below:

<appSettings>
  <add key="Email" value="[email protected]" />
  <add key="EmailPassword" value="ThePassword" />
</appSettings>

So long as each delevloper had their own config file they could keep their password secret but have generic code pull out the config file.

Ben Robinson
While we don't do it now, our mail servers are slated to be secured soon so that a password is required to send mail as well as retrieve mail from your mailbox. We'll probably relax this requirement for services accounts (which our web sites would run under), but for normal users that would be the case.
tvanfosson
hi - we do not want to send our passwords in email body//it is necessary for gmail server (for example)==however is it possble to invisible some codebehind lines?
LostLord
in this case we can not hash these passwords...
LostLord
hash passwords works when you are using web db / but in this case we shoult send passes like themselves...
LostLord
I have updated to show how to do what you require based on the code you posted.
Ben Robinson
@tvanfosson I realise some smtp servers require authentication before you relay through them, what i was didn't understand was why you would need a password for each person you wanted to email.
Ben Robinson
+1  A: 

I would suggest creating and using a service account, not your personal account, for sending email from a web site. If possible, have your mail system admins exempt this service account from requiring a password to send email. In my experience, admins are usually pretty good about making exceptions for lower risk service accounts (because it isn't used by any human for normal internet activity).

tvanfosson
thanks for your answer // but email and it's password in one of our problems and we can solve it by your solution //i made this thread to finding a way for invisible codebehind lines//is it possible?
LostLord
@Lost - no. it's not possible to hide code from the other developers. If they have access to the executable they can decompile the code and get access if they need it. The best you can do is store the credentials in a .config file that isn't part of your source code, then everyone can use their own. You certainly wouldn't want to keep source code out of SCM.
tvanfosson
thanks for your answers - it seems there is no way to hide codebehind from eachother(developers in a common team)thanks a lot
LostLord