When smtp mail returns a "password not accepted from server" - authentication

You get this error from phpmailer.
"Password not accepted from server: 535 Incorrect authentication data"
What causes this?

You must make sure that the Username given for the log-on is the same as the SetFrom email address.
This will return an error:
$mail->Username = "myemailaddress#gmail.com"; // GMAIL username
$mail->Password = "password"; // GMAIL password
$mail->SetFrom('mysetfromaddress#gmail.com', 'Pagelinks');
This should not.
$mail->Username = "mysetfromaddress#gmail.com"; // GMAIL username
$mail->Password = "password"; // GMAIL password
$mail->SetFrom('mysetfromaddress#gmail.com', 'Pagelinks');
When the Username and SetFrom do not match the authentication fails (according to an article found on Google).

Related

Way to verify username and password of user in aws cognito using adminInitiateAuth() method

Requirement:
Below code is having 2 functions. 1st verify the username and password of user and if it is true it trigger OTP in SMS(Default behavior of AWS as 2 factor authentication is enabled). But we do not want OTP in SMS. We want OTP in Email with custom template, so implemented 2nd function with AuthFlow: 'CUSTOM_AUTH'(and 2nd method works as expected).
We do not want OTP to be triggered in SMS(But also can not disable 2 factor auth because it is used in other use cases). Also, only need solution using aws-sdk. There are ways using amplify and other library but it is not useful in case of App client secret is there.
//verify username,password and send code in sms
response0 = await cognitoIdentityServiceProvider.adminInitiateAuth({
AuthFlow: 'ADMIN_NO_SRP_AUTH',
ClientId: tenant.cognitoClientId,
UserPoolId: tenant.cognitoUserPool,
AuthParameters: {
SECRET_HASH: crypto.createHmac('SHA256', tenant.cognitoClientSecret).update(username + tenant.cognitoClientId).digest('base64'),
USERNAME: username,
PASSWORD: password
}
}).promise();
// send code to email using custom auth flow
response1 = await cognitoIdentityServiceProvider.adminInitiateAuth({
AuthFlow: 'CUSTOM_AUTH',
ClientId: tenant.cognitoClientId,
UserPoolId: tenant.cognitoUserPool,
AuthParameters: {
SECRET_HASH: crypto.createHmac('SHA256', tenant.cognitoClientSecret).update(username + tenant.cognitoClientId).digest('base64'),
USERNAME: username,
PASSWORD: tenantId + secrets.PASSWORD_SECRET
}
}).promise();
Need solution where we can check username password using AuthFlow: 'CUSTOM_AUTH'(Can change lambda triggers) or any other way where OTP should not be triggered and able to check username and password correctly.

ERPNext: How can I generate user session without Password?

As an ERPNext fresher, I am creating a REST API for the mobile app, where the use case is, the Mobile user will send a request to do login using Face authentication, as a result of Face authentication at the mobile end, it will return User ID(same as ERPNext UserID).
As a Param, I will get UserID and other params of API request, here in response, I have to send a new session generated for that User.
Applied solution:
Tried Login by fetching password of user based on UserID, which basically gives encryption error for encrypted password.
Tried bypass login and generate new session, failed due to password not being added
Decrypt the password to use as param for new session
My current problem is, I don't have Password in normal format, and need to generate a valid user session, for the next operation post face recognization(face validation is already done through SDK).
You can use token based authentication for REST Api, based on your question when you receive emailid (same as erpnext user id), you can identify the user and generate api_key and api_secret, you can return these keys in response to your request, also you can store these secrets keys and use for future requests to authenticate it
You can refer docs here https://frappeframework.com/docs/user/en/api/rest#1-token-based-authentication
Below is sample code, please note code is not tested, posted just for reference
#frappe.whitelist(allow_guest=True)
def validate_user(email):
user_email = frappe.db.get_all('User', filters={'name': email}, fields=['name'])
user = frappe.get_doc('User', user_email[0]['name'])
api_generate = generate_keys(user.name)
user_resp = frappe.get_doc('User', user.name)
frappe.response["message"] = {
"status": 1,
"message": "Authentication success",
"api_key": user_resp.api_key,
"api_secret": api_generate,
"username": user.username,
"email": user_resp.email,
"role": user_resp.roles[0].role
}
def generate_keys(user):
user_details = frappe.get_doc('User', user)
api_secret = frappe.generate_hash(length=15)
if not user_details.api_key:
api_key = frappe.generate_hash(length=15)
user_details.api_key = api_key
frappe.db.set_value('User', user, 'api_secret', api_secret)
return api_secret

PHP mail function not working in cpanel using G Suit

I want to submit my form on email but PHP mail function not working in my hostgator cloud server, i am using G Suit on this server. Please help
You can use PHPMailer instead of server mailing as send emails from php not work in most host providers so PHPMailer solve your problem as you can send email over SMTP from php
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//Enable SMTP debugging.
$mail->SMTPDebug = 3;
//Set PHPMailer to use SMTP.
$mail->isSMTP();
//Set SMTP host name
$mail->Host = "smtp.gmail.com";
//Set this to true if SMTP host requires authentication to send email
$mail->SMTPAuth = true;
//Provide username and password
$mail->Username = "name#gmail.com";
$mail->Password = "super_secret_password";
//If SMTP requires TLS encryption then set it
$mail->SMTPSecure = "tls";
//Set TCP port to connect to
$mail->Port = 587;
$mail->From = "name#gmail.com";
$mail->FromName = "Full Name";
$mail->addAddress("name#example.com", "Recepient Name");
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent successfully";
}
?>
PHPMailer docs https://github.com/PHPMailer/PHPMailer/wiki/Tutorial

How to add a new flash message to devise.en.yml?

I want to display a new flash msg on logout under a particular condition.. I'm overriding the after_sign_out_path_for method in application_controller.rb. I have added a new msg in devise.en.yml too. How do I flash the new msg on logout when its redirected to sign in page???
application_controller.rb:
def after_sign_out_path_for(resource_or_scope)
if is_already_logged_in?
flash.keep[:notice] = t("devise.failure.concurrent")// IS NOT WORKING
new_user_session_path
else
new_user_session_path(resource)
end
end
devise.en.yml:
en:
devise:
confirmations:
confirmed: "Your account was successfully confirmed. You are now signed in."
send_instructions: "You will receive an email with instructions about how to confirm your account in a few minutes."
send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes."
failure:
already_authenticated: "You are already signed in."
inactive: "Your account was not activated yet."
invalid: "Invalid email or password."
invalid_token: "Invalid authentication token."
locked: "Your account is locked."
not_found_in_database: "Invalid email or password."
timeout: "Your session expired, please sign in again to continue."
unauthenticated: "You need to sign in or sign up before continuing."
unconfirmed: "You have to confirm your account before continuing."
// NEW MESSAGE ADDED
concurrent: "You are signed out due to concurrent sessions!"
mailer:
confirmation_instructions:
subject: "Confirmation instructions"

error send email with phpmailer in server domain but succed in localhost

i have detail error with this problem,
SMTP -> FROM SERVER:220-server.modulindo.com ESMTP Exim 4.77 #2 Wed, 11 Jul 2012 10:57:22 +0700 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
SMTP -> FROM SERVER: 250-server.modulindo.com Hello mail.modulindo.com [202.67.9.42] 250-SIZE 52428800 250-PIPELINING 250-AUTH PLAIN LOGIN 250 HELP
SMTP -> ERROR: Password not accepted from server: 535 Incorrect authentication data
SMTP -> FROM SERVER:250 Reset OK
please help me guys!?
i have a problem with phpmailer. i send email with phpmailer in localhost is succeed, but when i upload it in my server domain, there was an error happend. the error is..
SMTP Error: Could not authenticate. Mailer Error: SMTP Error: Could not authenticate.
this is my script..
....
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Mailer = "smtp";
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = "wasis85#gmail.com";
$mail->Password = "password";
$mail->From = "wasis85#gmail.com";
$mail->FromName = "Wasis Lukito";
$mail->AddAddress($ema[$ari_no],"wasis");
$mail->AddCC("wasisl85#yahoo.com");
$mail->AddReplyTo("wasisl85#yahoo.com","Wasis Lukito");
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = "Penolakan Data BPLPSE";
$mail->Body = "Alasan di tolak ";
$mail->AltBody = "This research is supported by Google.com";
...
i solved same problem with comment (or cancel) this line
// $mail->IsSMTP();
this because from some server i had same error: SMTP Error: Could not authenticate (also Password is incorrect...etc)
The script seems to be fine. I believe you have to check and make sure if your server supports SMTP or it has been properly configured for SMTP or not.