Registration form with salt and SHA1 encryption - zend-framework

I have a registration form and I am using zend_auth for my login, below is how the information is encrypted for secure login:
->setCredentialTreatment('SHA1(CONCAT(?,salt))');
I have the following register method so far:
public function addUser($first_name, $surname, $email, $username, $password, $salt, $age, $gender, $uni) {
$salt=substr(SHA1(mt_rand()),0,40);
$data = array(
'first_name' => $first_name,
'surname' => $surname,
'email' => $email,
'username' => $username,
'password' => $password,
'salt' => $salt,
'age' => $age,
'gender' => $gender,
'uni' => $uni,
);
$this->insert($data);
}
I need to add in the SHA1 encryption for the password here, but I am unsure how it will look. Any help would be awesome.
Thanks

$data = array(
'first_name' => $first_name,
'surname' => $surname,
'email' => $email,
'username' => $username,
'password' => sha1($password.$salt),
'salt' => $salt,
'age' => $age,
'gender' => $gender,
'uni' => $uni,
);

Related

Send email to all the rows from mysql in codeigniter

i need to send emails to all the rows in database table with their corresponsing data. i am able to send single emails by their id, but now i need to send in bulk. i have done in pure php but in codeigniter not able to figure out. how to do this.
my controller is
public function autoformcomplete()
{
$this->load->model('admin/Reminder_model');
$datan = $this->Reminder_model->autoformemail();
//this should be in whileloop, that i am not able to figure out
$email = $datan[0]['email'];
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'email-smtp.eu-west-1.amazonaws.com',
'smtp_port' => 587,
'smtp_crypto' => 'tls',
'smtp_user' => 'user',
'smtp_pass' => 'pass',
'mailtype' => 'text',
'charset' => 'utf-8',
);
$this->email->initialize($config);
$this->email->set_mailtype("html");
$this->email->set_newline("\r\n");
$this->email->set_crlf("\r\n");
$subject = "Complete Your Partially Filled Application-".$appid."";
$data['datan'] = $datan;
$mesg = $this->load->view('email/reminder/form_complete',$data,true);
$this->email->to($email);
$this->email->from('mail#mail.com','My Company');
$this->email->subject($subject);
$this->email->message($mesg);
$this->email->send();
echo "sent";
}
My Model is
public function autoformemail(){
$this->db->order_by('id', 'DESC');
$query = $this->db->get('appstbldata');
return $query->result_array();
}
Just use a foreach loop
public function autoformcomplete() {
$this->load->model( 'admin/Reminder_model' );
$datan = $this->Reminder_model->autoformemail();
foreach ( $datan as $index => $val ) {
// $val now references the current pointer to an element in your $datan array
$email = $val['email'];
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'email-smtp.eu-west-1.amazonaws.com',
'smtp_port' => 587,
'smtp_crypto' => 'tls',
'smtp_user' => 'user',
'smtp_pass' => 'pass',
'mailtype' => 'text',
'charset' => 'utf-8',
);
$this->email->initialize( $config );
$this->email->set_mailtype( "html" );
$this->email->set_newline( "\r\n" );
$this->email->set_crlf( "\r\n" );
$subject = "Complete Your Partially Filled Application-" . $appid . "";
$data['datan'] = $datan;
$mesg = $this->load->view( 'email/reminder/form_complete', $data, true );
$this->email->to( $email );
$this->email->from( 'mail#mail.com', 'My Company' );
$this->email->subject( $subject );
$this->email->message( $mesg );
$this->email->send();
echo "sent";
}
}
I dunno what your point of $data['datan'] = $datan; line is though

Yii2:- update record using update query for mongodb

I am trying to make update query using Yii2 for mongodb. I make following query:
$collection = Yii::$app->mongodb->getCollection('usermaster');
$arrUpdate = [
'firstName' => $fname,
'lastName' => $lname,
'email' => $email,
'is_visible' => $isvisibleUser,
'phoneNumber' => $phone,
'userName' => $uname,
];
$collection->update(['_id = 55a4957sd88423d10ea7c07d'],$arrUpdate);
But it shows follwoing error in firebug.
"NetworkError: 500 Internal Server Error - http://localhost/yii2angularseedmaster/frontend/web/category/corporateupdate?corpUserid=55a4957sd88423d10ea7c07d"
My insert query works perfectly but update query does not works.
Please tell me what is wrong in my query.
$collection->update(['_id' => $id],$arrUpdate);
Your code should be like this
$collection = Yii::$app->mongodb->getCollection('usermaster');
$arrUpdate = [
'firstName' => $fname,
'lastName' => $lname,
'email' => $email,
'is_visible' => $isvisibleUser,
'phoneNumber' => $phone,
'userName' => $uname,
];
$collection->update(['_id' => $id],$arrUpdate);

Cakephp email gives error : "Connection timed out"

I am sending email with CakePHP framework.
Following is the code I have added in function :
App::uses('CakeEmail', 'Network/Email');
$Email = new CakeEmail('gmail');
$Email->from(array(
ADMIN_EMAIL => 'kioui'
));
$Email->to('pankhiwalia#gmail.com');
$Email->subject('test');
$Email->emailFormat('text');
$p = $Email->send();
and under Config/email.php file I have added following smtp settings:
public $smtp = array(
'transport' => 'Smtp',
'from' => array(ADMIN_EMAIL => ADMIN_NAME),
'host' => 'ssl://localhost',
'username' => 'kiouiapp#kioui-apps.com',
'password' => 'Fr00Fr00',
'client' => null,
'log' => true,
'timeout' => '30',
'tls' => false,
'port' => 465,
);
Please tell me did I miss any line?

cake email internal error

So I am debugging some code that someone else wrote and it utilises the cakephp cake email thing. I have never used it before and have never written an email function before either.
When the function executes it outputs cakes standard: "Error: An Internal Error Has Occurred"
as well as this line:
SMTP Error: 535 5.7.8 http://support.google.com/mail/bin/answer.py?answer=14257 h66sm5396348yhb.7 - gsmtp
The code is here:
public function newAppEmail($email_addr, $password) {
$Email = new CakeEmail();
$Email->config('default');
$Email->sender(array('polarontest#gmail.com' => 'Polaron'));
$Email->from(array('polarontest#gmail.com' => 'Polaron'));
$Email->to($email_addr);
$Email->subject('Eligibility Check');
$Email->template('newapp');
$Email->emailFormat('text');
$Email->viewVars(array('name' => $this->request->data['Applicant']['first_name'], 'email' => $this->request->data['Applicant']['email'], 'password' => $password));
$Email->attachments(array(
'Polaron - PL Passport - Info Pack - 2013.pdf' => array(
'file' => APP . 'documents/Email_attachments/Polaron - PL Passport - Info Pack - 2013.pdf',
'mimetype' => 'pdf'),
));
$Email->send();
}
and this is the config file:
<?php
class EmailConfig {
public $default = array(
'transport' => 'Smtp',
'from' => array('email#email.com' => 'company name'),
'sender' => array('email#email.com' => 'company name'),
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'email#email.com',
'password' => 'password');
public $fast = array(
'transport' => 'Smtp',
'from' => array('email#email.com' => 'Test Mail name sender'),
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'email#email.com',
'password' => 'password');
}
Can anyone shed some light on what might be wrong and where I should look to fix it?
Well, SMTP Error 535 means that authentication fails, which is easy to find out.
The exception is thrown because of that. So get the right credentials and try again, this is not an issue of the php code but your credentials.
If your login / password is correct, test the configuration:
public $smtp = array(
'transport' => 'Smtp',
'from' => array('email#gmail.com' => 'Name'),
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'timeout' => 30,
'username' => 'email#gmail.com',
'password' => '**********',
'client' => null,
'log' => false,
'charset' => 'utf-8',
'headerCharset' => 'utf-8',
);

how to send smtp mail in cakephp 2

What I did
public $smtp = array(
'transport' => 'Smtp',
'from' => array('me#mydomain.com' => 'test'),
'host' => 'mail.mydomain.com',
'port' => 80,
'timeout' => 60,
'username' => 'me#mydomain.com',
'password' => 'me123',
'client' => null,
'log' => false,
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
$email = new CakeEmail('Smtp');
$result = $email->template('welcome_mail','default')
->emailFormat('html')
->to($to_email)
->from('me#mydomain.com')
->subject('Welcome')
->viewVars($contents);
if($email ->send('Smtp'))
{
echo ('success');
}
what I am doing wrong here?
Please can anyonce explain smtp settings here?
what is host,username,password,client?
Please guide me what is host
which username and password I have to set here
I would add the Email Config to your email.php file located in /app/Config/email.php , if it doesn't exist copy email.php.default to email.php, Change the smtp settings there
public $smtp = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'my#gmail.com',
'password' => 'secret'
);
At the top of your Controller above class Controller extends AppController add,
App::uses('CakeEmail', 'Network/Email');
Then to send an email, try
$Email = new CakeEmail();
$Email->from(array('me#example.com' => 'My Site'))
->to('you#example.com')
->subject('About')
->send('My message');
To test emails what I usually do is send them to the Cake Logs,
**In /app/Config/email.php, include: ( The log output should be /app/tmp/logs/debug.log )
public $test = array(
'log' => true
);
Also doing this add 'test' to your $Email variable like,**
$Email = new CakeEmail('test');